How to fix npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name is blacklisted in npm
The EINVALIDPACKAGENAME error with 'blacklisted' occurs when your package.json uses a reserved name like 'node_modules' or a name that conflicts with npm's internal directories. Rename your package to a valid, unique name.
Quick fix
Fixes EINVALIDPACKAGENAME
{
"name": "your-package-name"
}- Check your package name
- Delete and regenerate package-lock.json
- Remove macOS .DS_Store files
- Clean install node_modules
{"name": "your-package-name"}npm ERR! code EINVALIDPACKAGENAMEnpm ERR! Invalid package name: name is blacklisted
What this error means
This error occurs when your package.json contains a package name that npm has blacklisted. Certain names are reserved because they would conflict with npm's internal workings or Node.js core modules. The most common blacklisted name is "node_modules"—if npm allowed a package with this name, installing it would cause chaos with the dependency directory structure. Similarly, names like ".bin", "package.json", and Node.js core module names (fs, path, http, etc.) are restricted. The validation happens both during `npm install` (if a dependency has an invalid name) and `npm publish` (for your own package).
Typical symptoms
- Error message: Invalid package name "node_modules"
- npm install fails with EINVALIDPACKAGENAME
- Error references .DS_Store or .bin as invalid names
- Package name conflicts with Node.js core module
- npm update -g fails with invalid package name
- Corrupted package-lock.json references blacklisted names
- macOS .DS_Store files causing npm errors
Common causes
- Package name is 'node_modules', '.bin', or other reserved name
- Name matches a Node.js core module (fs, path, http, etc.)
- Corrupted package-lock.json or package.json
- .DS_Store files (macOS) being parsed as packages
- Manual edit introduced invalid dependency name
- Git merge conflict corrupted package files
- Temporary npm directories appearing as packages
How to fix "npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name is blacklisted"
Look at the name field in your package.json:
{
"name": "your-package-name"
}Invalid names include:
- node_modules
- .bin
- package.json
- Node.js core modules (fs, path, http, child_process, etc.)
- Names starting with . or _
- Names with uppercase letters or spaces
Change to a valid, descriptive name.
Corrupted lock files often cause this error:
rm package-lock.json
npm installThis regenerates the lock file from scratch based on your package.json.
On macOS, these hidden files can confuse npm:
# Remove from node_modules
find node_modules/ -name '.DS_Store' -type f -delete
# Remove from entire project
find . -name '.DS_Store' -type f -delete
# Prevent future creation (optional)
echo '.DS_Store' >> .gitignoreRemove everything and start fresh:
rm -rf node_modules package-lock.json
npm cache clean --force
npm installLook in package.json for invalid entries:
{
"dependencies": {
"https": "*", // Invalid - remove this
"node_modules": "1.0.0" // Invalid - remove this
}
}These sometimes appear after bad merges or manual edits. Remove them and run npm install.
If you're trying to publish and your desired name conflicts:
{
"name": "@yourusername/fs-utils"
}This avoids conflicts with core modules while keeping a meaningful name.
Advanced notes
Package naming rules:
npm package names must:
- Be lowercase only
- Be 214 characters or fewer
- Not start with . or _
- Not contain spaces or special characters except - and _
- Not be a Node.js core module name
- Not be a reserved name (node_modules, .bin, etc.)
Use the validate-npm-package-name package to check:
npx validate-npm-package-name "your-name"For CI/CD:
If this error appears suddenly in CI:
1. Check recent commits for package.json/lock file changes
2. Look for merge conflicts that weren't properly resolved
3. Ensure .DS_Store files aren't committed to the repo
4. Clear CI cache and rebuild
Git hooks to prevent issues:
Add to .git/hooks/pre-commit:
#!/bin/sh
find . -name '.DS_Store' -type f -deleteThis removes .DS_Store files before each commit.
Frequently asked questions
- What does "EINVALIDPACKAGENAME" mean?
- json contains a package name that npm has blacklisted. js core modules. The most common blacklisted name is "node_modules"—if npm allowed a package with this name, installing it would cause chaos with the dependency directory structure.
- How do I fix "EINVALIDPACKAGENAME"?
- The EINVALIDPACKAGENAME error with 'blacklisted' occurs when your package.json uses a reserved name like 'node_modules' or a name that conflicts with npm's internal directories. Rename your package to a valid, unique name.
- What causes "EINVALIDPACKAGENAME"?
- Package name is 'node_modules', '.bin', or other reserved name Name matches a Node.js core module (fs, path, http, etc.) Corrupted package-lock.json or package.json
- Is the "EINVALIDPACKAGENAME" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚npm Official Documentation
- 💬
- 🔗
- 🐙GitHub #6425: npm/cli(GitHub)