npm "Invalid package name" / "Invalid Version" - Fix a Malformed package.json
npm validates the name and version fields of every package.json against strict naming and semver rules. A name with illegal characters, or a version that is not valid semver, makes npm reject the manifest outright.
What this error means
npm aborts immediately with Invalid package name or Invalid Version, naming the offending value. Nothing installs because npm cannot accept the manifest as published or as a workspace.
npm error code EINVALIDPACKAGENAME
npm error Invalid package name "My_App": name can only contain URL-friendly
npm error characters; name cannot start with an underscore.
# or
npm error Invalid Version: "v1.0"Common causes
Illegal characters or casing in name
npm names must be lowercase, URL-safe, and cannot start with a dot or underscore. Uppercase letters, spaces, or special characters are rejected.
A version that is not valid semver
A version like v1.0, 1.0, or latest is not valid semver. npm requires a full MAJOR.MINOR.PATCH (optionally with pre-release/build metadata).
How to fix it
Correct the name and version fields
Use a lowercase URL-safe name and a valid semver version.
// package.json
{
"name": "my-app",
"version": "1.0.0"
}Validate before committing
- Run
npm pkg get name versionto read the current values. - Ensure the name is lowercase, URL-safe, and not prefixed with
./_. - Ensure the version is full semver (
1.2.3), notv1.2or a tag.
How to prevent it
- Keep
namelowercase and URL-safe;versionfull semver. - Use
npm versionto bump rather than hand-editing. - Lint package.json in CI before installing.