The "Invalid name" error occurs when your package.json contains a name that doesn't follow npm naming rules. Names must be lowercase, URL-safe, and follow specific conventions.
npm has strict rules for package names to ensure they work correctly as URLs, directory names, and command-line arguments. The name field in package.json must conform to these rules. Invalid names often occur when copying from other platforms, using organization naming conventions, or simply not being aware of npm's restrictions.
Valid npm names must:
- Be lowercase
- Not start with . or _
- Not contain spaces
- Be URL-safe
- Be under 214 characters
- Not match Node.js core modules
Convert to lowercase:
// WRONG
{
"name": "MyAwesomePackage"
}
// CORRECT
{
"name": "my-awesome-package"
}Use hyphens or underscores:
// WRONG
{
"name": "my awesome package!"
}
// CORRECT
{
"name": "my-awesome-package"
}Scoped packages use @org/name:
// WRONG
{
"name": "@myorg_mypackage"
}
// CORRECT
{
"name": "@myorg/my-package"
}Don't use Node.js core module names:
// WRONG - matches core module
{
"name": "http"
}
// CORRECT
{
"name": "my-http-utils"
}Check name validity:
# npm validates on publish
npm publish --dry-run
# Or use validate-npm-package-name
npx validate-npm-package-name "your-package-name"Package names are globally unique on npm - check availability before committing to a name. Use scopes (@org/package) for organization packages. npm audit uses the package name for security tracking. Consider SEO and discoverability when choosing names. Once published, the name cannot be changed (only the entire package can be deprecated).
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 ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error