npm publish 404 Not Found - PUT
Problem
The nearest issue is #1626 but it's about using npm to get package, and it look solved for most user. Here it's about npm publishing package in CI, and it's not solved for now. Current Behavior: https://framagit.org/1000i100/g1lien/-/jobs/1072053 [code block] Expected Behavior: Successful publish of my package from docker in gitlab-CI with npm_token authentication. (it works yesterday on my laptop with npm login, but not with npm_token in CI). Steps To Reproduce: ex. steps to reproduce the behavior: 1. Fork this : https://framagit.org/1000i100/g1lien 2. change the package name and add your npm token 3. push it with a tag on a gitlab with CI active. It should reproduce the problem. Environment: https://framagit.org/1000i100/g1lien/-/blob/master/.gitlab-ci.yml#L5 https://framagit.org/1000i100/g1lien/-/jobs/1072052#L17 - OS: Docker in gitlab with image: node:current - Node: v14.7.0 - NPM: 6.14.7
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix npm publish 404 Not Found in GitLab CI
The 404 Not Found error during npm publish in GitLab CI is likely due to incorrect npm token configuration or scope issues with the package name. When using npm_token in CI, it is essential to ensure that the token is correctly set up in the environment variables and that the package name matches the expected scope in the npm registry.
Awaiting Verification
Be the first to verify this fix
- 1
Verify npm token configuration
Ensure that the npm token is correctly set in the GitLab CI/CD environment variables. Navigate to your GitLab project, go to Settings > CI/CD > Variables, and check that the variable 'NPM_TOKEN' is set with the correct value.
bashecho $NPM_TOKEN - 2
Check package name and scope
Ensure that the package name in your package.json matches the expected format for scoped packages. If your package is scoped (e.g., @username/package-name), make sure that the npm token has permission to publish to that scope.
bashcat package.json | grep name - 3
Update .gitlab-ci.yml for npm publish
Modify your .gitlab-ci.yml file to include the npm publish command with the correct authentication. Ensure that the npm registry URL is set to the correct endpoint.
bashecho '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc && npm publish - 4
Run CI pipeline
After making the changes, commit and push your changes to trigger the CI pipeline. Monitor the job logs to confirm that the npm publish command executes successfully without a 404 error.
bashgit add .gitlab-ci.yml .npmrc && git commit -m 'Fix npm publish configuration' && git push
Validation
Check the CI job logs to confirm that the npm publish command completes successfully without returning a 404 error. Additionally, verify that the package appears in your npm registry under your account.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep