Npmjs.com/package and https://npm.pkg.github.com/package doesn't match, github requires onwer

Hi,

I’m not able to find a solution about this problem https://stackoverflow.com/questions/62604672/npmjs-com-package-and-https-npm-pkg-github-com-package-doesnt-match-github-r

Following this documentation https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages I get a wrong npm install package url doesn’t exist: “npm install @orsifrancesco/react-mini-alert-confirm@1.1.5”

Which is the solution to publish the package to github without errors?

Thank you in advance

@orsifrancesco,

There are 2 different .npmrc configurations you can use when publishing a package:

With this one, only packages in the @OWNER scope will connect to GitHub:

//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
@OWNER:registry=https://npm.pkg.github.com

With this one, GitHub will act as a proxy for packages that aren’t in the @OWNER scope:

//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
registry=https://npm.pkg.github.com/OWNER

I made a .npmrc file including registry=https://npm.pkg.github.com ,

The configuration in the Stack Overflow question appears to be a hybrid between the two, which won’t work. GitHub needs to know the OWNER of the package being published.

You will also need to add the following element to your package.json:

"repository" : {
    "type" : "git",
    "url": "ssh://git@github.com/OWNER/REPOSITORY.git",
    "directory": "packages/name"
  },

Could you try doing this, creating one of the .npmrc files above and then:

export GITHUB_TOKEN=<PAT with  repo, read:packages and write:packages scope>
npm publish

Please let me know if you have any more luck with this. If it works, I’ll answer on Stack Overflow as well.

1 Like

@jcansdale,

Thank you for your answer :slight_smile:

I tried your solution with another package, unfortunately I get the same result.

Maybe I was thinking wrong about the possibility to publish to github.com and npmjs.com with just npm publish command.

@orsifrancesco,

Maybe I was thinking wrong about the possibility to publish to github.com 1 and npmjs.com 1 with just npm publish command.

I’ve done some experimenting and it seems this is possible. Could you try the following:

  1. Make sure you don’t have a .npmrc file with the registry= or @OWNER:registry= setting
  2. Login to GitHub Package: npm login --registry=https://npm.pkg.github.com
  3. Publish your package: npm publish --registry=https://npm.pkg.github.com

Here is the workflow I used to test this with:

on:
  push:

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - name: create package.json
      run: |
        cat <<- EOF > package.json
        {
          "name": "@${{ github.repository }}",
          "version": "1.0.0-g${{ github.sha }}",
          "repository": "https://github.com/${{ github.repository }}"
        }
        EOF
    - run: echo '//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}' > .npmrc
    - run: npm publish --registry=https://npm.pkg.github.com
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Is that the kind of thing you were after?

1 Like

Sorry, I’m replying only now.
Tried now… Same problem… but I really appreciate :slight_smile:

@orsifrancesco,

Tried now… Same problem… but I really appreciate :slight_smile:

Could you create an example repository with what you’re trying to do? That way I can fork it and send you a PR with suggested changes. If you could set up a GitHub Actions workflow as well so I can see the errors.

Thanks,
Jamie.