Skip to content
Latchkey

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 output
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
// package.json
{
  "name": "my-app",
  "version": "1.0.0"
}

Validate before committing

  1. Run npm pkg get name version to read the current values.
  2. Ensure the name is lowercase, URL-safe, and not prefixed with ./_.
  3. Ensure the version is full semver (1.2.3), not v1.2 or a tag.

How to prevent it

  • Keep name lowercase and URL-safe; version full semver.
  • Use npm version to bump rather than hand-editing.
  • Lint package.json in CI before installing.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →