Registry / testing / npm-package-json-lint

npm-package-json-lint

JSON →
library10.3.0jsnpmunverified

Configurable linter for package.json files. Version 10.3.0 requires Node >=22 and npm >=10. Enforces standards like valid data types, lowercase names, valid semver, presence of required fields, and dependency correctness. Ships TypeScript types and supports both CLI and programmatic usage with flat config (ESLint-style) since v10.0.0. Frequent releases; actively maintained.

npm install npm-package-json-lint
INSTALL
IMPORT
SIG · NPM-PACKAGE-JSON-L
N
npm-package-json-lint
testingjavascriptv10.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Linter
import { Linter } from 'npm-package-json-lint'
const Linter = require('npm-package-json-lint')
ESM-only since v10.0.0. Use named import.
lintFiles
import { lintFiles } from 'npm-package-json-lint'
const lintFiles = require('npm-package-json-lint').lintFiles
Named export. CommonJS require will not work directly.
NpmPackageJsonLintConfig
import type { NpmPackageJsonLintConfig } from 'npm-package-json-lint'
TypeScript type export for configuration objects.

Programmatic usage: instantiate Linter with rules, lint package.json, and log issues.

import { Linter } from 'npm-package-json-lint'; const linter = new Linter({ rules: { 'require-name': 'error', 'require-version': 'error', 'valid-values-name-scope': ['error', ['@myorg']], 'prefer-absolute-version-dependencies': 'error', }, }); const results = linter.lintFiles(['package.json']); if (results.results[0].issues.length > 0) { console.log('Issues found:', JSON.stringify(results.results[0].issues, null, 2)); } else { console.log('No issues found.'); }
npmPkgJsonLint --version
Debug
Known issues
breakingDropped support for Node.js 20 in v10.0.0; requires Node >=22.
fix
Upgrade Node.js to version 22 or higher.
affects: >=10.0.0
breakingv10.0.0 switched from CommonJS to ESM and introduced flat config (ESLint-style).
fix
Use ESM imports and flat config format. See migration guide.
affects: >=10.0.0
breakingDropped support for Node.js 18 in v9.0.0.
fix
Upgrade Node.js to version 20 or higher (or 22 for v10+).
affects: >=9.0.0
breakingDropped support for Node.js 16 in v8.0.0.
fix
Upgrade Node.js to version 18 or higher.
affects: >=8.0.0
deprecatedThe 'prefer-alphabetical-dependencies' rule is deprecated in favor of 'prefer-alphabetical'.
fix
Use 'prefer-alphabetical' rule instead.
affects: >=7.0.0
Errors
Common errors & fixes
Error: Cannot find module 'npm-package-json-lint'
Missing or incorrect import/require statement when using CommonJS after v10.0.0.
fix
Use ESM import: import { Linter } from 'npm-package-json-lint';
npmPackageJsonLint is not a function
Using the old CommonJS require pattern that returns an object exported via module.exports after v10.0.0.
fix
Use named imports: import { lintFiles } from 'npm-package-json-lint';
TypeError: Linter is not a constructor
Importing Linter incorrectly (e.g., default import) when it's a named export.
fix
Import Linter as a named export: import { Linter } from 'npm-package-json-lint';
Upgrade
Version history
10.3.0latest on npm
Audit
Dependencies
cosmiconfigrequiredConfiguration loading
ignorerequiredIgnore file support
semverrequiredSemver validation
Agent activity
2 hits · last 30 days
node
2
Resources
npm-package-json-lint — npm install npm-package-json-lint · libregistry