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.
Fixes npm ERR! 422 Unprocessable Entity
# Validate package.json
npm pkg get
# Or use jsonlint
npx jsonlint package.json
# Check specific field
npm pkg get name version# Validate package.jsonnpm pkg get# Or use jsonlintnpx jsonlint package.json# Check specific fieldnpm pkg get name versionnpm ERR! 422 Unprocessable Entity
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.