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.
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).
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.
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.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error