This error occurs when your package name contains characters not allowed by npm. Package names must be lowercase, URL-friendly, and follow specific naming rules.
npm enforces strict naming rules for packages to ensure they work correctly across different systems and can be used in URLs. When you run `npm init` or have an invalid name in package.json, npm rejects names that don't follow these rules. Package names must: - Be lowercase only - Not contain spaces - Not start with a dot (.) or underscore (_) - Not contain special characters like @, #, $, %, &, *, etc. (except in scoped packages) - Be URL-friendly - Be 214 characters or less
Valid package names can only contain:
- Lowercase letters (a-z)
- Numbers (0-9)
- Hyphens (-)
- Underscores (_) - but not at the start
- Dots (.) - but not at the start
Examples:
❌ Invalid: "My-Cool-Package"
✅ Valid: "my-cool-package"
❌ Invalid: "my package"
✅ Valid: "my-package"
❌ Invalid: "my@package"
✅ Valid: "my-package"
❌ Invalid: ".my-package"
✅ Valid: "my-package"Edit your package.json:
{
"name": "my-valid-package-name",
"version": "1.0.0"
}Convert your name:
- Replace spaces with hyphens
- Convert to lowercase
- Remove special characters
If you're using npm init and it's using your folder name:
# Rename folder to valid name
mv "My Project" my-project
cd my-project
npm init -yFor organization or personal namespaces, use scoped packages:
{
"name": "@mycompany/my-package"
}Scoped names follow the format @scope/package-name where both parts must follow naming rules.
Reserved names: npm blocks certain names:
- Node.js core modules: fs, http, path, etc.
- npm commands: install, publish, test, etc.
- Previously unpublished names that were squatted
Name validation: Use the validate-npm-package-name package to check names:
npx validate-npm-package-name "your-package-name"Legacy names: Some very old packages have names that wouldn't be valid today (with capitals or special chars). New packages must follow current rules.
Private packages: Even if you never publish, follow naming conventions. Invalid names can cause issues with tools and scripts that parse package.json.
npm error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred
How to fix "spawn git ENOENT" in npm
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm