FG
๐Ÿ’ป Software๐Ÿ› ๏ธ Developer ToolsMicrosoft

npm publish 404 Not Found - PUT

Fresh3 days ago
Mar 14, 20260 views
Confidence Score94%
94%

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

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Fix npm publish 404 Not Found in GitLab CI

Medium Risk

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. 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.

    bash
    echo $NPM_TOKEN
  2. 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.

    bash
    cat package.json | grep name
  3. 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.

    bash
    echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc && npm publish
  4. 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.

    bash
    git 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

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejs