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 ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"