publint
raw JSON → 0.3.18 verified Fri May 01 auth: no javascript
publint is a tool for linting npm packaging errors to ensure compatibility across environments. The current stable version is 0.3.18, with frequent patch releases addressing edge cases in export mapping, file existence checks, and CJS/ESM interop warnings. It differentiates from tsc or api-extractor by focusing specifically on package.json validation, including exports, imports, main, types fields, and CommonJS default export issues. It provides a CLI, API, and online playground, and supports Node >=18.
Common errors
error SyntaxError: Unexpected token '?' ↓
cause Using Node <18 which lacks support for ?? operator in publint code
fix
Upgrade Node to 18 or later.
error ERR_MODULE_NOT_FOUND: Cannot find module 'publint' ↓
cause Using CommonJS require() with ESM-only package
fix
Add "type": "module" in package.json and use import statements.
error Error: Cannot find module 'publint/utils' ↓
cause Incorrect import path; utility exports are under 'publint/utils' subpath
fix
Import from 'publint/utils' instead of 'publint'.
Warnings
breaking Requires Node >=18; older versions will fail ↓
fix Upgrade Node to >=18.
breaking ESM-only since v0.3.0; CommonJS require will not work ↓
fix Use import statements instead of require().
deprecated Some rules may change severity in future; check docs ↓
fix Stay updated via changelog.
Install
npm install publint yarn add publint pnpm add publint Imports
- publint wrong
import publint from 'publint'correctimport { publint } from 'publint' - check wrong
const check = require('publint').checkcorrectimport { check } from 'publint' - getPkgPathValue wrong
import { getPkgPathValue } from 'publint'correctimport { getPkgPathValue } from 'publint/utils'
Quickstart
import { check, formatMessage } from 'publint';
import { readFile } from 'node:fs/promises';
const pkgJson = JSON.parse(await readFile('./package.json', 'utf-8'));
const results = await check({ pkg: pkgJson, rootDir: '.' });
for (const msg of results.messages) {
console.log(formatMessage(msg));
}