The EINVALIDPACKAGENAME error for capital letters occurs because npm requires all package names to be lowercase. Convert your package name to lowercase, using hyphens to separate words.
This error occurs when your package name contains uppercase letters. npm requires all package names to be lowercase—no exceptions for new packages. This rule was introduced to prevent confusion on case-insensitive file systems (like Windows and macOS default). If both 'MyPackage' and 'mypackage' were allowed, they'd conflict on these systems. It also prevents typosquatting attacks where 'Lodash' could be registered to catch typos of 'lodash'. Some old packages in the registry still have uppercase letters (they were grandfathered in), but you cannot publish new packages with capitals.
Change your package name to lowercase, using hyphens to separate words:
// Invalid
{
"name": "MyAwesomePackage"
}
// Valid
{
"name": "my-awesome-package"
}Common conversions:
- MyPackage → my-package
- myPackage → my-package
- MYPACKAGE → mypackage
After renaming, update references throughout your project:
# Find files that might reference the old name
grep -r "MyPackage" --include="*.js" --include="*.ts" --include="*.json"Update:
- Import/require statements
- README.md
- Documentation
- CI/CD configurations
npm package naming best practices:
// Good: lowercase with hyphens
"name": "react-router-dom"
"name": "lodash-es"
"name": "date-fns"
// Also valid: underscores (less common)
"name": "socket_io"
// Valid: scoped with lowercase
"name": "@angular/core"Avoid underscores at the start (they're reserved).
Check your name before publishing:
npx validate-npm-package-name "my-package-name"Output shows if the name is valid and what issues exist if not.
If you're renaming an existing package directory:
# On case-insensitive systems (macOS, Windows), use a temp name
mv MyPackage temp-my-package
mv temp-my-package my-packageDirect mv MyPackage my-package won't work on case-insensitive file systems because they see it as the same name.
The lowercase requirement was introduced around npm v1.3. Existing packages with uppercase letters were grandfathered in and still work—they just can't publish new versions with uppercase names.
If you absolutely need a mixed-case display name, you can use the displayName field in package.json for documentation purposes:
{
"name": "mypackage",
"displayName": "MyPackage"
}Note that displayName isn't officially standardized by npm but is used by some tools like VS Code extensions.
For organizations transitioning from private registries that allowed uppercase, you may need to rename packages when publishing to npm. Create aliases or wrapper packages if backwards compatibility is needed.
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