How to fix npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name is blacklisted in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025· 127 views

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"
}
  1. Check your package name
  2. Delete and regenerate package-lock.json
  3. Remove macOS .DS_Store files
  4. Clean install node_modules
npm — error
{
"name": "your-package-name"
}
npm ERR! code EINVALIDPACKAGENAME
npm 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

  1. Package name is 'node_modules', '.bin', or other reserved name
  2. Name matches a Node.js core module (fs, path, http, etc.)
  3. Corrupted package-lock.json or package.json
  4. .DS_Store files (macOS) being parsed as packages
  5. Manual edit introduced invalid dependency name
  6. Git merge conflict corrupted package files
  7. Temporary npm directories appearing as packages

How to fix "npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name: name is blacklisted"

1Check your package name

Look at the name field in your package.json:

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.

2Delete and regenerate package-lock.json

Corrupted lock files often cause this error:

bash
rm package-lock.json
npm install

This regenerates the lock file from scratch based on your package.json.

3Remove macOS .DS_Store files

On macOS, these hidden files can confuse npm:

bash
# 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' >> .gitignore
4Clean install node_modules

Remove everything and start fresh:

bash
rm -rf node_modules package-lock.json
npm cache clean --force
npm install
5Check for corrupted dependencies

Look in package.json for invalid entries:

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

6Use a scoped name if generic name is taken

If you're trying to publish and your desired name conflicts:

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

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

bash
#!/bin/sh
find . -name '.DS_Store' -type f -delete

This 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