Not Found - PUT https://npm.pkg.github.com/package-name

后端 未结 4 1852
萌比男神i
萌比男神i 2021-02-19 03:31

I\'m trying to upload a package on GPR (Github Package registry). I log in successfully:

npm login --registry=https://npm.pkg.github.com

and th

4条回答
  •  孤街浪徒
    2021-02-19 03:47

    As hinted by other answers here, the root cause of the above error is that GPR (unlike https://www.npmjs.com/) requires that packages have a scope.

    However, it seems that all other suggested solutions (updating package.json and etc.) would not allow to keep publishing the package to https://www.npmjs.com/ without a scope. Here's my solution that allows both:

    Assuming that:

    1. package.json contains simple package name without scope as often is the case when publishing public packages to https://www.npmjs.com/
    2. GitHub Workflow is configured using GitHub's Node.js Package template

    Add additional step to publish-gpr job before the run: npm ci default step in order to dynamically insert current repository's owner into package name in package.json:

    - name: Insert repository owner as scope into package name
      run: |
        node < JSON.parse(data)).then((json) => {
            json.name = '@$(echo "$GITHUB_REPOSITORY" | sed 's/\/.\+//')/' + json.name;
            console.info('Package name changed to %s', json.name);
            return fs.writeFile('package.json', JSON.stringify(json), 'utf8');
        }).catch(error => {
            console.error(error);
            process.exit(1);
        });
        EOF
    

提交回复
热议问题