The HTTP 422 Unprocessable Entity error occurs when npm's request is syntactically correct but semantically invalid. This often indicates issues with package.json content or registry validation failures.
HTTP 422 means the server understands the request format but cannot process it due to semantic errors. In npm's context, this typically means your package.json or package content violates registry rules even though it's valid JSON. This differs from 400 Bad Request (malformed request) - with 422, the syntax is fine but the content doesn't make sense to the registry.
Check for issues:
# Validate package.json
npm pkg get
# Or use jsonlint
npx jsonlint package.json
# Check specific field
npm pkg get name versionEnsure name follows rules:
{
"name": "my-package"
}Rules:
- Lowercase only
- No spaces (use hyphens)
- Under 214 characters
- No leading dots or underscores
- No URL-unsafe characters
Version must be valid semver:
{
"version": "1.0.0"
}Valid formats: 1.0.0, 1.0.0-beta.1, 1.0.0-rc.1+build.123
Ensure all required fields exist:
{
"name": "package-name",
"version": "1.0.0",
"description": "What your package does",
"main": "index.js"
}Dependencies must be properly formatted:
{
"dependencies": {
"lodash": "^4.17.21",
"express": "~4.18.0"
}
}Valid specifiers: ^, ~, >=, exact versions, git URLs.
If present, repository must be valid:
{
"repository": {
"type": "git",
"url": "https://github.com/user/repo.git"
}
}Or shorthand: "repository": "github:user/repo"
npm registries may have different validation rules - what works on npmjs.com may fail on private registries. Use npm publish --dry-run to test without actually publishing. For scoped packages, ensure scope is properly configured. Some enterprise registries require additional metadata like license or author fields.
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