npm-package-json-lint

raw JSON →
10.3.0 verified Fri May 01 auth: no javascript

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.

error Error: Cannot find module 'npm-package-json-lint'
cause Missing or incorrect import/require statement when using CommonJS after v10.0.0.
fix
Use ESM import: import { Linter } from 'npm-package-json-lint';
error npmPackageJsonLint is not a function
cause 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';
error TypeError: Linter is not a constructor
cause 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';
breaking Dropped support for Node.js 20 in v10.0.0; requires Node >=22.
fix Upgrade Node.js to version 22 or higher.
breaking v10.0.0 switched from CommonJS to ESM and introduced flat config (ESLint-style).
fix Use ESM imports and flat config format. See migration guide.
breaking Dropped support for Node.js 18 in v9.0.0.
fix Upgrade Node.js to version 20 or higher (or 22 for v10+).
breaking Dropped support for Node.js 16 in v8.0.0.
fix Upgrade Node.js to version 18 or higher.
deprecated The 'prefer-alphabetical-dependencies' rule is deprecated in favor of 'prefer-alphabetical'.
fix Use 'prefer-alphabetical' rule instead.
npm install npm-package-json-lint
yarn add npm-package-json-lint
pnpm add npm-package-json-lint

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.');
}