Node.js2 minutes to read

Why does npm ci fail on my host when npm install works locally?

Distinguish a missing lockfile from a manifest mismatch or an install flag difference, then reproduce your Node.js deployment from a clean checkout.

What npm is checking

npm ci installs the dependency tree recorded in a lockfile. It fails when there is no compatible lockfile or when its package information disagrees with package.json. A local npm install can update the lockfile during installation. If that update never reached the host, the two commands are testing different inputs. npm ci reference.

For example, you add Express locally and commit only package.json. Your machine already has Express in node_modules, and your tests pass. On a clean deployment, npm ci sees a dependency that the shipped lockfile does not describe.

Follow the first error from the install step

  1. If npm cannot find a lockfile, open Files and check whether package.json and package-lock.json are together at the directory where your command runs. A zip can introduce a wrapper folder.
  2. If npm reports a mismatch, run npm install in the intended local package, review the changes in both files and keep them together in the same commit.
  3. If the project intentionally uses an install setting such as legacy-peer-deps, reproduce that setting in CI and on the host. Commit the project-level npm configuration only after checking it for credentials.

Reproduce the deployment before pushing again

Check the revision out into a fresh folder and run the same install, build and start commands as the host. A clean checkout excludes packages left over from local experiments. Capture the first specific npm error if it still fails. A registry access error or a native module build failure calls for a different fix than a lockfile mismatch.

Deploy the verified revision. For a connected repository, compare its commit ID with Recent deploys. For a file upload, check that the replacement lockfile landed next to the intended manifest. Verify a GitHub deployment.