The EINVALIDTAGNAME error with spaces occurs when npm encounters a tag name containing spaces or special characters. This typically happens when using npm tag commands or dist-tags with spaces, or malformed package names.
npm validates distribution tags (dist-tags) and package names using strict rules to ensure compatibility with URL encoding. Any character that would be encoded by JavaScript's encodeURIComponent function—including spaces, special characters like @, ^, >, =, and slashes—triggers this error. npm prevents these invalid tag names to maintain consistency in package distribution and prevent issues with package registry operations. This error is a validation check that npm enforces when creating dist-tags, installing packages with invalid tags, and publishing packages with problematic tag specifications.
If you're using npm tag or npm install commands, verify there are no spaces around special characters. Spaces around @ in scoped packages are a common cause.
# Incorrect:
npm install @ namespace / package --save
npm tag [email protected] 'my tag'
# Correct:
npm install @namespace/package --save
npm tag [email protected] my-tagTag names should use hyphens instead of spaces to separate words.
If your project directory contains spaces, it can trigger this error during npm init or npm install. Rename your folder to use hyphens or camelCase.
# Rename from:
cd "My Project"
npm init
# Rename to:
cd my-project
npm initUse underscores or hyphens instead of spaces in directory names.
Check your package.json file for any malformed package names or dependency version specifiers that contain spaces.
// Problematic:
{
"name": "my package",
"dependencies": {
"@scope / pkg": "1.0.0"
}
}
// Fixed:
{
"name": "my-package",
"dependencies": {
"@scope/pkg": "1.0.0"
}
}Package names must be lowercase and can only contain hyphens, underscores, and alphanumeric characters.
When creating or managing distribution tags, use hyphens instead of spaces. Tag names are case-sensitive and must not contain spaces.
# Incorrect:
npm dist-tag add [email protected] 'release candidate'
# Correct:
npm dist-tag add [email protected] rc
npm dist-tag add [email protected] betaCommon valid dist-tags: latest, next, beta, rc, stable, dev
The EINVALIDTAGNAME error is fundamentally about URL safety. npm uses encodeURIComponent internally when transmitting package metadata to the registry. Characters that encode to special sequences (spaces become %20, @ becomes %40, etc.) can cause parsing issues in the registry. Some older npm versions (pre-v7) were inconsistent—allowing invalid tag creation but failing on installation. Upgrading npm often reveals these hidden issues.
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 E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error
npm ERR! code ENOTDIR npm ERR! ENOTDIR: not a directory
How to fix "ENOTDIR: not a directory" in npm