npm publish fails / `npm publish <folder>` publishes from cwd folder
See original GitHub issueI have configured semantic-release/npm
with pkgRoot = './dist'
On CI/CD command is npx -w my-package semantic-release
CI run 28 Logs:
[1:20:01 PM] [semantic-release] [@semantic-release/git] › ℹ Prepared Git release: my-package-v1.1.2
[1:20:03 PM] [semantic-release] › ✔ Created tag my-package-v1.1.2
[1:20:03 PM] [semantic-release] › ℹ Start step "publish" of plugin "@semantic-release/npm"
[1:20:03 PM] [semantic-release] [@semantic-release/npm] › ℹ Publishing version 1.1.2 to npm registry on dist-tag latest
+ my-package@0.0.0-dev.1
[1:20:04 PM] [semantic-release] [@semantic-release/npm] › ℹ Published my-package@1.1.2 to dist-tag @latest on https://registry.npmjs.org/
Note: my-package@0.0.0-dev.1
is a result of npm publish
CI run 29 Logs:
2022-07-31T13:06:50.035Z semantic-release:plugins options for @semantic-release/npm/verifyConditions: { pkgRoot: '/root/packages/my-package/dist' } 2022-07-31T13:06:50.040Z semantic-release:plugins options for @semantic-release/npm/prepare: { pkgRoot: '/root/packages/my-package/dist' } 2022-07-31T13:06:50.040Z semantic-release:plugins options for @semantic-release/npm/publish: { pkgRoot: '/root/packages/my-package/dist' } 2022-07-31T13:06:50.041Z semantic-release:plugins options for @semantic-release/npm/addChannel: { pkgRoot: '/root/packages/my-package/dist' } [1:06:51 PM] [semantic-release] [@semantic-release/npm] › ℹ Write version 1.1.2 to package.json in /root/packages/my-package/dist v1.1.2 [1:06:52 PM] [semantic-release] › ✔ Completed step "prepare" of plugin "@semantic-release/npm" [1:06:52 PM] [semantic-release] [@semantic-release/git] › ℹ Found 1 file(s) to commit 2022-07-31T13:06:52.112Z semantic-release:git commited files: [ 'CHANGELOG.md' ] [1:06:52 PM] [semantic-release] [@semantic-release/git] › ℹ Prepared Git release: my-package-v1.1.2 [1:06:53 PM] [semantic-release] › ✔ Created tag my-package-v1.1.2 [1:06:53 PM] [semantic-release] › ℹ Start step "publish" of plugin "@semantic-release/npm" [1:06:53 PM] [semantic-release] [@semantic-release/npm] › ℹ Publishing version 1.1.2 to npm registry on dist-tag latest npm ERR! code E403 npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/my-package - You cannot publish over the previously published versions: 0.0.0-dev.1. shortMessage: 'Command failed with exit code 1: npm publish /root/packages/my-package/dist --userconfig /tmp/6d5920eb12a6009b40553b60ba81d8e8/.npmrc --tag latest --registry https://registry.npmjs.org/', command: 'npm publish /root/packages/my-package/dist --userconfig /tmp/6d5920eb12a6009b40553b60ba81d8e8/.npmrc --tag latest --registry https://registry.npmjs.org/', escapedCommand: 'npm publish "/root/packages/my-package/dist" --userconfig "/tmp/6d5920eb12a6009b40553b60ba81d8e8/.npmrc" --tag latest --registry "https://registry.npmjs.org/"', exitCode: 1, signal: undefined, signalDescription: undefined, stdout: '', stderr: 'npm ERR! code E403\n' + 'npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/my-package - You cannot publish over the previously published versions: 0.0.0-dev.1.\n' + 'npm ERR! 403 In most cases, you or one of your dependencies are requesting\n' + 'npm ERR! 403 a package version that is forbidden by your security policy, or\n' + 'npm ERR! 403 on a server you do not have access to.\n' + failed: true, timedOut: false, isCanceled: false, killed: false, pluginName: '@semantic-release/npm' } Error: Command failed with exit code 1: npm publish /root/packages/my-package/dist --userconfig /tmp/6d5920eb12a6009b40553b60ba81d8e8/.npmrc --tag latest --registry https://registry.npmjs.org/ ##[error]Process completed with exit code 1.
As you can see from logs version 1.1.2
is correctly written to package.json in dist
folder, but following command is failing
npm publish "/root/packages/my-package/dist" --userconfig "/tmp/6d5920eb12a6009b40553b60ba81d8e8/.npmrc" --tag latest --registry "https://registry.npmjs.org/"
It’s trying to publish 0.0.0-dev.1
which is in package.json
in /root/packages/my-package
(equals to process.cwd()
)
But if I execute this command locally, it works without errors.
Corresponding npm publish command:
const result = execa(
'npm',
['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd, env, preferLocal: true}
);
Looks like that execa
has issues with cwd
or preferLocal
(or its combination).
Update: Some additional research results here in https://github.com/semantic-release/npm/issues/504#issuecomment-1201540336
Issue Analytics
- State:
- Created a year ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
npm-publish - npm Docs
The publish will fail if the package name and version combination already exists in the specified registry. Once a package is published with...
Read more >npm publish isn't including all my files - Stack Overflow
The problem was I had a files array in package.json. If this is present, then only the specified files get published, and everything...
Read more >dotnet publish command - .NET CLI | Microsoft Learn
dotnet publish - Publishes the application and its dependencies to a folder for deployment to a hosting system.
Read more >How to publish apps to NPM - Educative.io
Make sure your package's name does not currently exist on NPM. Otherwise, you will get an error while publishing. You can use the...
Read more >Publishing Packages to NPM -- newline - Fullstack.io
Not only has npm's short process for publishing packages led to the explosive ... In the current directory, you will find a tar...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As it is a blocking issue for me, I have made a PR to fix it.
@travi, I would be very pleased if you could approve it. Thanks 🙏
I made some research. I patched node_modules/@semantic-release/npm/lib/publish.js
Same result, it maybe issue with npm itself (my version is 8.11.0), also I do no see any related bug fixes in changelog of execa (after v5)
I’ve tried another trick:
And it works!
So it definitly something wrong with npm and
npm publish <folder>
command,npm publish
for current folder works ok.