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 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
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm