npm Publish Problems That Keep Coming Up in Forums

Browse any JavaScript help forum for a week and the same handful of npm publish failures appear over and over. None of them are exotic; most come from registry rules that are documented but easy to miss. Here are the recurring questions, paraphrased, with the answers that usually resolve them. Always check the current npm Docs for the exact wording of each rule.

"It says I cannot publish over a previously published version."

The npm registry treats a published version number as permanent. Even if you unpublish it, the same name and version cannot be used again. The fix is to bump the version, for example with npm version patch, and publish the new number. This is a feature: anyone who installed 1.4.2 can rely on 1.4.2 always meaning the same bytes.

"My package name is rejected even though nobody uses it."

The registry blocks names that are too similar to existing packages, for example differing only in punctuation, in order to reduce typosquatting. The usual answer is to publish under a scope you control, such as @your-org/name. Scoped packages are private by default when published from some account types, so the first public publish typically needs:

npm publish --access public

Or set it once in the manifest:

{
  "name": "@your-org/tiny-parser",
  "publishConfig": { "access": "public" }
}

"The published package is missing my build output."

npm decides what to include from the files array, then .npmignore, then .gitignore. If your dist/ folder is git-ignored and there is no files field or .npmignore, it is excluded. Run npm pack --dry-run to see the exact file list before publishing, and prefer an explicit files allow-list:

"files": ["dist", "README.md", "LICENSE"]

The README, LICENSE and package.json are always included regardless.

"Publishing asks for a one-time password in CI and fails."

If your account enforces two-factor authentication for publishing, an interactive prompt cannot be answered in a pipeline. The documented options are granular access tokens scoped to the package, or publishing from a supported CI provider with provenance enabled. Forum threads frequently suggest disabling 2FA; resist that, because your publish credentials are exactly what an attacker wants.

"I published by mistake. Can I take it back?"

npm allows unpublishing within a limited window and under specific conditions, which are set out in the npm unpublish policy. Outside those conditions, the supported route is npm deprecate with a message, followed by a fixed release. Deprecation keeps installs working while warning users, which is usually kinder anyway.

Quick pre-publish checklist from these threads

Related pages