How to fix npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name can no longer contain more than 214 characters in npm
The EINVALIDPACKAGENAME error for length occurs when your package name exceeds 214 characters. Shorten your package name or use a scoped name to reduce the character count.
Quick fix
Fixes EINVALIDPACKAGENAME
node -e "console.log(require('./package.json').name.length)"- Check your package name length
- Shorten the package name
- Use scopes efficiently
- Check for corrupted data
node -e "console.log(require('./package.json').name.length)"npm ERR! code EINVALIDPACKAGENAMEnpm ERR! Invalid package name: name can no longer contain more than 214 characters
What this error means
This error occurs when your package name (including the scope, if any) exceeds npm's 214-character limit. The limit exists for practical reasons: very long names cause issues with file paths, URLs, and display in npm's web interface. The 214-character limit was increased over time (from 50 to 128 to 214) to accommodate longer descriptive names, but it caps there. Scoped packages (@org/name) count the full string including the @ and /. In practice, this error is rare because meaningful package names are usually well under 214 characters. If you hit this limit, it's often due to corrupted package data or accidentally including extra text in the name field.
Typical symptoms
- npm publish fails with 'name too long' error
- npm install fails on a dependency with overly long name
- Error during npm init with very descriptive name
- Corrupted package-lock.json with malformed entries
- CI/CD fails validating package.json
Common causes
- Package name in package.json exceeds 214 characters
- Scoped package name (@scope/name) total exceeds limit
- Accidentally pasted extra text into name field
- Corrupted package-lock.json with malformed package names
- Build tool generated an overly verbose package name
How to fix "npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name can no longer contain more than 214 characters"
Count the characters in your package.json name:
node -e "console.log(require('./package.json').name.length)"If it's over 214, you need to shorten it.
Good package names are concise but descriptive:
// Too long (don't do this)
{
"name": "my-super-awesome-incredible-fantastic-utility-library-for-handling-http-requests-with-caching-and-retries"
}
// Better
{
"name": "http-cache-retry"
}Use abbreviations and focus on the core functionality.
Scopes add characters, so keep them short:
// Longer total: 25 characters
{
"name": "@my-organization/utils"
}
// Shorter total: 15 characters
{
"name": "@myorg/utils"
}Remember: the @ and / count toward the 214-character limit.
If the error appears during install, inspect your lock file:
# Find entries with long names
grep -o '"[^"]*":' package-lock.json | awk 'length > 100'Delete corrupted entries or regenerate the lock file:
rm package-lock.json
npm installCheck your name meets all requirements:
npx validate-npm-package-name "your-package-name"This validates length, characters, and reserved words all at once.
Advanced notes
The 214-character limit has historical reasons. Originally npm had a 50-character limit, then 128, and eventually 214 to match the longest existing package name in the registry when the limit was raised.
On Windows, total file path length can cause additional issues. With deeply nested node_modules, a 214-character package name plus the path could exceed Windows' 260-character path limit. Modern npm uses a flat node_modules structure to mitigate this, but be aware if you're supporting older npm versions.
If you're building an internal package registry (like Verdaccio), you might be able to configure different limits, but staying within npm's standards ensures compatibility if you ever publish publicly.
Frequently asked questions
- What does "EINVALIDPACKAGENAME" mean?
- This error occurs when your package name (including the scope, if any) exceeds npm's 214-character limit. The limit exists for practical reasons: very long names cause issues with file paths, URLs, and display in npm's web interface. The 214-character limit was increased over time (from 50 to 128 to 214) to accommodate longer descriptive names, but it caps there.
- How do I fix "EINVALIDPACKAGENAME"?
- The EINVALIDPACKAGENAME error for length occurs when your package name exceeds 214 characters. Shorten your package name or use a scoped name to reduce the character count.
- What causes "EINVALIDPACKAGENAME"?
- Package name in package.json exceeds 214 characters Scoped package name (@scope/name) total exceeds limit Accidentally pasted extra text into name field
- 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
- ๐npm Official Documentation
- ๐
- ๐ฌ
- ๐