How to fix npm ERR! Invalid name in npm

npmBEGINNERMEDIUMUpdated Dec 6, 2025ยท 150 views

The "Invalid name" error occurs when your package.json contains a name that doesn't follow npm naming rules. Names must be lowercase, URL-safe, and follow specific conventions.

Quick fix

Fixes npm ERR! Invalid name

// WRONG
{
  "name": "MyAwesomePackage"
}

// CORRECT
{
  "name": "my-awesome-package"
}
  1. Check naming rules
  2. Fix uppercase letters
  3. Replace spaces and special chars
  4. Fix scope format
npm โ€” error
// WRONG
{
"name": "MyAwesomePackage"
}
// CORRECT
{
"name": "my-awesome-package"
}
npm ERR! Invalid name

What this error means

npm has strict rules for package names to ensure they work correctly as URLs, directory names, and command-line arguments. The name field in package.json must conform to these rules. Invalid names often occur when copying from other platforms, using organization naming conventions, or simply not being aware of npm's restrictions.

Typical symptoms

  • npm publish fails with invalid name
  • npm install fails for local package
  • Error mentions specific naming rule
  • Package works locally but not on registry
  • Scoped package name incorrect
  • Name copied from another source

Common causes

  1. Uppercase letters in name
  2. Spaces in name
  3. Starts with dot or underscore
  4. Contains URL-unsafe characters
  5. Name too long (>214 chars)
  6. Name matches core Node.js module
  7. Invalid scope format

How to fix "npm ERR! Invalid name"

1Check naming rules

Valid npm names must:

- Be lowercase
- Not start with . or _
- Not contain spaces
- Be URL-safe
- Be under 214 characters
- Not match Node.js core modules

2Fix uppercase letters

Convert to lowercase:

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

// CORRECT
{
  "name": "my-awesome-package"
}
3Replace spaces and special chars

Use hyphens or underscores:

json
// WRONG
{
  "name": "my awesome package!"
}

// CORRECT
{
  "name": "my-awesome-package"
}
4Fix scope format

Scoped packages use @org/name:

json
// WRONG
{
  "name": "@myorg_mypackage"
}

// CORRECT
{
  "name": "@myorg/my-package"
}
5Avoid reserved names

Don't use Node.js core module names:

json
// WRONG - matches core module
{
  "name": "http"
}

// CORRECT
{
  "name": "my-http-utils"
}
6Validate before publish

Check name validity:

bash
# npm validates on publish
npm publish --dry-run

# Or use validate-npm-package-name
npx validate-npm-package-name "your-package-name"

Advanced notes

Package names are globally unique on npm - check availability before committing to a name. Use scopes (@org/package) for organization packages. npm audit uses the package name for security tracking. Consider SEO and discoverability when choosing names. Once published, the name cannot be changed (only the entire package can be deprecated).

Frequently asked questions

What does "npm ERR! Invalid name" mean?
npm has strict rules for package names to ensure they work correctly as URLs, directory names, and command-line arguments. json must conform to these rules. Invalid names often occur when copying from other platforms, using organization naming conventions, or simply not being aware of npm's restrictions.
How do I fix "npm ERR! Invalid name"?
The "Invalid name" error occurs when your package.json contains a name that doesn't follow npm naming rules. Names must be lowercase, URL-safe, and follow specific conventions.
What causes "npm ERR! Invalid name"?
Uppercase letters in name Spaces in name Starts with dot or underscore
Is the "npm ERR! Invalid name" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading