Error Knowledge Base NPM EINVALIDPACKAGENAME

npm ERR! code EINVALIDPACKAGENAME

npm rejected the package name because it does not follow npm naming rules, such as invalid characters, uppercase letters, or reserved names.

What This Error Means

npm rejected the package name because it does not follow npm naming rules, such as invalid characters, uppercase letters, or reserved names.

How to Fix It

Open package.json and inspect the name field first.

For unscoped packages, use a lowercase URL-safe name with no spaces (for example my-package).

For scoped packages, use @scope/package-name and keep both the scope and package segment lowercase.

If the package is not meant to be published, keep a valid name anyway so npm metadata validation passes.

Retry with npm pack --dry-run or the original npm command after fixing the name.

Why It Happens

The name field in package.json contains uppercase letters, spaces, or other non-URL-safe characters.

An unscoped package name starts with a leading dot or underscore.

A scoped name is malformed and does not follow the @scope/package-name shape.

How to Verify

Print the current value:npm pkg get name

Run node -p "require('./package.json').name" and confirm it matches the corrected value.

Run npm pack --dry-run and confirm EINVALIDPACKAGENAME no longer appears.

Manual package name checks

Inspect package.json directly and confirm the name field is present.

If the package is scoped, confirm it contains exactly one slash after the scope, for example @acme/widget.

Check for uppercase letters or spaces before retrying the npm command.

Examples

Invalid package name: "MyPackage"  # uppercase letters
Invalid package name: ".internal-tool"  # leading dot without a scope
Valid package name: "my-package"
Valid scoped package name: "@acme/build-tools"

How npm validates package names

npm validates package metadata locally before it needs to talk to the registry.

Package names end up in URLs, CLI arguments, and local folder paths, so invalid names are rejected early.

Because this validation happens first, registry availability and auth are usually unrelated to EINVALIDPACKAGENAME.

Prevention Tips

Keep package names lowercase and URL-safe from the start.

Validate package.json changes in CI with npm pack --dry-run before publishing.

Use a review checklist for scoped package names so the scope and package segments stay consistent.

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list