How to fix npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name can no longer contain capital letters in npm
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.
Quick fix
Fixes EINVALIDPACKAGENAME
// Invalid
{
"name": "MyAwesomePackage"
}
// Valid
{
"name": "my-awesome-package"
}- Convert to lowercase with hyphens
- Update all references
- Consider naming conventions
- Validate your name
// Invalid{"name": "MyAwesomePackage"}// Valid{"name": "my-awesome-package"}npm ERR! code EINVALIDPACKAGENAMEnpm ERR! Invalid package name: name can no longer contain capital letters
What this error means
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.
Typical symptoms
- npm publish fails with 'cannot contain capital letters' error
- npm init rejects name with uppercase characters
- Error when package.json name has camelCase or PascalCase
- Build tools reject project names with capitals
- CI/CD fails at package validation stage
Common causes
- Package name uses camelCase (myPackage)
- Package name uses PascalCase (MyPackage)
- Name copied from class or variable name with capitals
- Habit from other ecosystems that allow uppercase
- Corrupted package-lock.json with mixed-case entries
How to fix "npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name can no longer contain capital letters"
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.
Advanced notes
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.
Frequently asked questions
- What does "EINVALIDPACKAGENAME" mean?
- 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).
- How do I fix "EINVALIDPACKAGENAME"?
- 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.
- What causes "EINVALIDPACKAGENAME"?
- Package name uses camelCase (myPackage) Package name uses PascalCase (MyPackage) Name copied from class or variable name with capitals
- Is the "EINVALIDPACKAGENAME" error serious?
- It is a low-severity error — more of a blocker than a risk. The steps above resolve it.