How to fix npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name can no longer contain capital letters in npm

npmBEGINNERLOWUpdated Dec 6, 2025· 137 views

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"
}
  1. Convert to lowercase with hyphens
  2. Update all references
  3. Consider naming conventions
  4. Validate your name
npm — error
// Invalid
{
"name": "MyAwesomePackage"
}
// Valid
{
"name": "my-awesome-package"
}
npm ERR! code EINVALIDPACKAGENAME
npm 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

  1. Package name uses camelCase (myPackage)
  2. Package name uses PascalCase (MyPackage)
  3. Name copied from class or variable name with capitals
  4. Habit from other ecosystems that allow uppercase
  5. 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"

1Convert to lowercase with hyphens

Change your package name to lowercase, using hyphens to separate words:

json
// Invalid
{
  "name": "MyAwesomePackage"
}

// Valid
{
  "name": "my-awesome-package"
}

Common conversions:
- MyPackage → my-package
- myPackage → my-package
- MYPACKAGE → mypackage

2Update all references

After renaming, update references throughout your project:

bash
# 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

3Consider naming conventions

npm package naming best practices:

json
// 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).

4Validate your name

Check your name before publishing:

bash
npx validate-npm-package-name "my-package-name"

Output shows if the name is valid and what issues exist if not.

5Handle cross-platform issues

If you're renaming an existing package directory:

bash
# On case-insensitive systems (macOS, Windows), use a temp name
mv MyPackage temp-my-package
mv temp-my-package my-package

Direct 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:

json
{
  "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.

Official resources & further reading