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 notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm