The EINVALIDPACKAGENAME error occurs when your package name starts with a period (.) or underscore (_). Remove the leading character or use a scoped package name instead.
This error occurs when your package name begins with a dot (.) or underscore (_). npm prohibits these characters at the start of package names for several reasons: Names starting with dots are typically hidden files/directories on Unix systems (.gitignore, .env, .npmrc). If npm allowed packages with these names, they could conflict with configuration files or be accidentally hidden in file listings. Names starting with underscores were historically used for npm's internal purposes and are reserved for potential future use. The error often appears when system files like .DS_Store (macOS) or temporary directories are accidentally detected as packages during npm operations.
Remove the leading dot or underscore from your package.json:
// Invalid
{
"name": ".my-package"
}
// Valid
{
"name": "my-package"
}Or use a scoped name:
{
"name": "@myorg/my-package"
}Delete macOS system files from your project and node_modules:
# Remove from current directory and subdirectories
find . -name '.DS_Store' -type f -delete
# Remove from global npm directory
find /usr/local/lib/node_modules -name '.DS_Store' -type f -delete
# If using nvm
find ~/.nvm -name '.DS_Store' -type f -deleteAdd to .gitignore to prevent committing them:
.DS_StoreDelete npm's temporary directories that may have been left behind:
# Remove .npm-* directories from node_modules
rm -rf node_modules/.npm-*
# Remove from global directory
rm -rf /usr/local/lib/node_modules/.npm-*These directories are created during installation and should be cleaned up automatically, but sometimes remain after interrupted installs.
For Angular projects with __ngcc_entry_points__ errors:
# Remove the artifact
rm -rf node_modules/__ngcc_entry_points__.json
# Clear Angular cache
rm -rf .angular
# Reinstall
rm -rf node_modules package-lock.json
npm installIf the issue persists, do a full clean reinstall:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installFor global packages:
npm cache clean --force
npm update -gScoped packages (@scope/name) technically allow the package name part to start with a dot or underscore after the slash, but this is discouraged and may cause issues with some tools.
The .DS_Store problem is particularly common when:
- macOS users commit node_modules to git
- Shared network drives are used for development
- node_modules is copied between systems
To permanently prevent .DS_Store creation in a directory:
defaults write com.apple.desktopservices DSDontWriteNetworkStores trueFor CI/CD pipelines, always use npm ci instead of npm install to ensure a clean, reproducible installation that won't pick up stray files.
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