`npm` in Github Actions not able to access private repository dependency

I have a react native app that uses a native module which is in a different repository. Both my application and the module library are in private repos on Github, under my company’s organization. But both are private repos.

I have the module listed in my package.json file like so:

  "dependencies": {
    "react-native-cellular-info": "https://github.com/repeaterstore/react-native-cellular-info",
  }

And I have a Github Action that checks out the repository and does a yarn install:

      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
      - run: yarn install

But I get this message:

npm verb npm  v6.14.12
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://github.com/repeaterstore/react-native-cellular-info.git
npm ERR! 
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/repeaterstore/react-native-cellular-info.git/' not found
npm ERR! 
npm ERR! exited with error code: 128
npm verb exit [ 1, true ]
npm timing npm Completed in 569ms

At first I thought this was an authorization issue, and used this action along with an access token to ensure that the container has access to my private repos. My configuration now looks like:

    steps:
      - name: Setup git credentials
        uses: fusion-engineering/setup-git-credentials@v2
        with:
          credentials: ${{secrets.GIT_CREDENTIALS}}
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
      # other stuff...

I’m even able to clone the private repository now:

It clearly has access but yet when I try installing, it doesn’t work. It gives me the same

npm ERR! remote: Repository not found.

error. It actually looks like the error is happening when npm is trying to run this command:

npm ERR! /usr/bin/git ls-remote -h -t https://github.com/repeaterstore/react-native-cellular-info.git

Apparently this command doesn’t have any output. I’ve tried it on my own machine, and I’m getting this:

$ git ls-remote -h -t https://github.com/repeaterstore/react-native-cellular-info.git
ae5f720660d1d329349ea7b4c938f3dcd22dd5fe	refs/heads/main

I suspected that maybe npm can’t find the Github registry, but I have other dependencies that ARE hosted on Github but are not private, and they install just fine.

  "dependencies": {
    "react-native-maps": "https://github.com/ArshanKhanifar/react-native-maps#29720262881b9cffd9378f92be2fbb8f28b9f09e",
  }

So I’m really confused why npm can’t find my Github project despite having access to it. Any help is greatly appreciated!

Thanks :heart:

Hi @ArshanKhanifar :wave:

Hopefully this issue has been resolved, but if not then you could perhaps use the full URL to the private github repository that includes credentials, but expose them via the secrets variables, rather than hardcode:

"package-name": "git+https://<github_token>:x-oauth-basic@github.com/<user>/<repo>.git"

Another option is to also get an SSH key available on the repo/action workflow and use this syntax:

git+ssh://git@github.com:user_name/node_project.git

See this stackoverflow answer too: node.js - How to use private Github repo as npm dependency - Stack Overflow

1 Like

I actually tried a whole bunch of things and eventually solved this, but I think what particularly worked was making a .yarnrc file and adding this line to it:

"@repeaterstore:react-native-cellular-info" "https://npm.pkg.github.com"

1 Like

Gotcha. Thanks for the update!

1 Like