Thursday, April 14, 2022

[SOLVED] Npm install on GitHub Pull Request fails for the package referenced from a public GitHub repository

Issue

In the package.json file, I have added a dependency that is referencing one of our public repositories. The dependency in the package.json looks like below:

    "ffprobe-static": "git+https://github.com/company-name/repo-name.git",

I can successfully run npm install locally and use this dependency, but when I push this code, our GitHub workflows where we execute npm install fails with the below error:

npm ERR! Warning: Permanently added the RSA host key for IP address 'x.x.x.x' to the list of known hosts.
npm ERR! [email protected]: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

I don't understand the reason for this error, since the repository we are referencing is public, and also I can access the same repository when I install dependencies locally.

Note that the repository that is running this code is a private repository, but the referenced repository is public, but under the same organization.


Solution

You might try a config to force https URLs, at least for testing, in your GitHub workflow:

- name: Fix URL access
      run: echo -e '[url "https://github.com/"]\n  insteadOf = "ssh://[email protected]/"' >> ~/.gitconfig
    - name: Checkout server
      uses: actions/checkout@v2
      ...

Or (as in here, just to illustrate where you can put the git config insteadOf command):

on: push
jobs:
  check-elm:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Checkout submodules
      shell: bash
      run: |
        # From https://github.com/actions/checkout/issues/116#issuecomment-583221947
        git config --global url."https://github.com/".insteadOf
          ssh://[email protected]/
        git submodule sync --recursive
        git -c "http.extraheader=Authorization: basic ${{secrets.GITHUB_ACCESS_TOKEN}}" -c protocol.version=2 submodule update --init --force --recursive --depth=1
    - uses: actions/setup-node@v1
      with:
        node-version: '8.16.0'
    - run: npm run test


Answered By - VonC
Answer Checked By - Candace Johnson (WPSolving Volunteer)