npm-package-exports-audit
Audit packed npm tarballs and package.json exports across ESM, CommonJS, and TypeScript consumers to catch missing entrypoints, condition ordering bugs, and declaration mismatches.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: npm-package-exports-auditdescription: "Audit packed npm tarballs and package.json exports across ESM, CommonJS, and TypeScript consumers to catch missing entrypoints, condition ordering bugs, and declaration mismatches."category: developmentrisk: safesource: selfsource_type: selfdate_added: "2026-12-01"author: Koushik-Katkamtags: [npm, exports, esm, commonjs, typescript, package-audit]npm Package Exports Audit
Overview
Audit the actual packed tarball (.tgz) from the perspective of downstream ESM, CommonJS, and TypeScript consumers. Packages routinely pass in-repo unit tests via workspace symlinks, TypeScript path aliases, or unbuilt source folders while breaking downstream installers because files, .npmignore, publishConfig.exports, condition ordering, or dual-module declaration files are wrong in the packed artifact.
Distinction from existing skills:
npm-supply-chain-checkvets one public npm package for malware, CVEs, publisher changes, and typosquatting before installation without packing or validating consumer module resolution.effect-smol-package-developmentmanages Effect v4 monorepo workspace registration, barrels, and changesets inside an Effect workspace.pre-release-reviewaudits git diffs for general production deploy readiness (migrations, secrets, rollout order).javascript-typescript-typescript-scaffold,turborepo-caching, andvercel-vgpucover initial project templates, build caching, and WebGPU shader tooling rather than generic packed tarball consumer verification.
This skill focuses exclusively on consumer-side package surface verification of an existing .tgz tarball or an authorized local package built into a .tgz.
When to Use
- Before tagging or publishing an npm library when consumers use ESM (
import), CommonJS (require), or TypeScript (moduleResolution: "nodenext"/"node16"/"bundler"). - When downstream users report
ERR_PACKAGE_PATH_NOT_EXPORTED,MODULE_NOT_FOUND, wrong CJS/ESM entrypoint selection, or TypeScript declaration errors (Could not find a declaration file/ module-kind mismatch) that do not reproduce inside the monorepo. - After editing
"exports","main","module","types","files",".npmignore", or"publishConfig"inpackage.json. - Do not use this skill for pre-install malware/CVE vetting of untrusted public packages (
npm-supply-chain-check) or general release diff readiness (pre-release-review).
Prerequisites
- Local Node.js (tested on Node.js 24.21.0; ESM/CJS condition semantics and
require(esm)support vary across Node 20, 22, and 24 — record your target Node version) andnpmCLI (npm-cli.jsfor trusted source packing and--offline --ignore-scriptsinstallation). - Optional: local
tsc(typescript) for checking declaration resolution in a synthetic TypeScript consumer. - Trust gate:
- Existing untrusted tarball (
.tgz): Inspect statically using a maintained, bounded, non-extracting archive reader configured with explicit compressed/decompressed size limits, member-size and entry-count limits, and rejection of traversal paths, symlinks, and hardlinks (choosing a maintained library alone does not enforce bounds unless explicitly configured). Never call the fixture'sreadTarballSnapshotorstaticAuditPackedTarballhelpers on untrusted tarballs—they decompress the entire archive into memory without production resource bounds and are strictly limited to trusted synthetic fixtures. - Untrusted source directory: Never install, package,
import(),require(), or runtscon untrusted source directories. Do not presentnpm pack --ignore-scriptsornpm install --ignore-scriptsas a sandbox or sufficient protection for arbitrary untrusted source packaging or module execution (--ignore-scriptsskips npm lifecycle hooks only, not build plugins or code evaluation). - Runtime consumer checks (
import,require,tsc): Require trusted, authorized packages or synthetic reproductions.
- Existing untrusted tarball (
- No network access, npm registry authentication, paid tools, or package publishing is required.
How It Works
1. Inspect the immutable tarball statically first
Never substitute the workspace package.json, src/ layout, or a fresh npm pack --dry-run against source when auditing an existing .tgz artifact:
- Read
package/package.jsonand the member file list directly from the target.tgzarchive without extracting files or following symlinks (use an explicitly bounded, maintained, non-extracting reader on untrusted.tgzfiles; limitreadTarballSnapshot/staticAuditPackedTarballstrictly to trusted synthetic fixtures). Source directories often drift from already-built.tgzartifacts, and build tooling can rewritepublishConfig.exportsorworkspace:*ranges during packing. - Synthetic-fixture
exportsinspection & authoritative runtime checks: In trusted synthetic fixtures,collectExportLeaves/staticAuditPackedTarballinspect literalexportstargets against tarball members, check"types"before runtime conditions and"default"last at each nesting object level, check wildcard patterns (*), and recordnullexclusions. For fallback arrays,collectExportLeavesuses a narrow synthetic-fixture heuristic that marks later array items as shadowed only after seeing a preceding string starting with./; it does not implement general Node.js package-target validation, active-condition selection, nested target resolution, or full fallback-array semantics, andmissingRequired/missingFallbackare fixture inspection results rather than authoritative general resolver classifications. Keep real installed-consumer runtime checks (for example confirming["./missing.cjs", "./present.cjs"]fails CommonJSrequirewithMODULE_NOT_FOUNDeven when./present.cjsexists) as authoritative for the specific cases they exercise. - Manual manifest checklist (separate from
exportsharness): verifymain,module, top-leveltypes,bin, anddependenciesfor unresolvedworkspace:*orcatalog:ranges inside the packedpackage/package.json. See exports condition matrix.
2. Verify trusted packed tarballs with isolated consumers
For trusted, authorized packages (or synthetic test fixtures), follow packed consumer verification:
- On trusted, authorized local source only, build the target
.tgzartifact (npm pack --ignore-scripts --pack-destination <tmp>) or audit an existing trusted tarball. - Create isolated temporary consumer directories outside the monorepo workspace with
NODE_PATHandNODE_OPTIONScleared so workspace symlinks, rootnode_modules, andtsconfig.jsonpathscannot mask missing files. - Install the
.tgzoffline with lifecycle scripts disabled (npm install --offline --ignore-scripts --no-audit --no-fund <tarball.tgz>). - Execute separate ESM (
import), CommonJS (require), and TypeScript (tsc --noEmitwith"moduleResolution": "nodenext") checks by passing explicit argument vectors toprocess.execPath(shell: false; never build unquotedcmd.exeshell strings). - Assert actual exported runtime values, TypeScript diagnostics + line/column locations, and blocked subpath errors unconditionally — do not treat process exit
0alone as sufficient, and do not skip failing type checks. Note that Node.js 20.19+ / 22.12+ / 24 supports synchronousrequire(esm)for eligible ES modules without top-levelawait(top-levelawaitthrowsERR_REQUIRE_ASYNC_MODULE, while older Node releases throwERR_REQUIRE_ESM), so verify the resolved target path and module format explicitly when CommonJS consumers need a.cjsentry point or legacy Node support.
3. Report findings with environment scope
Separate verified results from untested surfaces:
- Record the exact Node.js, npm, and TypeScript versions used during checks, plus the
.tgzSHA-256 when auditing a release artifact. - List static tarball findings separately from workspace source state.
- List consumer verification results per module system (ESM, CJS, TypeScript ESM/CJS types, blocked
nullsubpaths), including exact error codes (MODULE_NOT_FOUND,ERR_PACKAGE_PATH_NOT_EXPORTED,TS7016,TS2307,TS2345) and observed values. - State explicitly which consumer environments were not tested (for example, Webpack, Vite, Node 20 without
require(esm)vs Node 24, or React Native Metro resolver).
Examples
Inspect a broken vs fixed package tarball using the self-contained harness in packed consumer verification:
User request: "Check why our library tarball works in ESM imports but fails in CommonJS consumers."
Inputs: Existing .tgz release artifact (or synthetic packed fixtures in isolated temp directories).
Expected diagnostic: In-memory tarball audit parses package/package.json inside the .tgz (even if source on
disk has since been edited) and flags missing ./dist/cjs/index.cjs. Packed ESM consumer exits 0 and
returns "hello, world"; packed CJS consumer exits 1 with MODULE_NOT_FOUND. A second defect keeping
dist/cjs/index.cjs while omitting dist/cjs/index.d.cts passes both runtime checks (exit 0) but fails
TypeScript nodenext CJS with exit 2 (TS7016). Fixing both makes ESM, CJS, and TypeScript consumers exit 0
and reject ./plugins/internal/secret in both runtime (ERR_PACKAGE_PATH_NOT_EXPORTED) and tsc (TS2307).
Limitations
- Runtime consumer verification checks the installed Node.js and TypeScript versions only; resolver edge cases in bundlers (Vite, Rollup, esbuild, Webpack) or older Node.js releases require testing in those target tools.
- Static inspection alone cannot detect runtime side effects or dynamic
require()calls inside compiled code. - Untrusted third-party tarballs and untrusted source directories must stop at non-executing archive inspection; runtime consumer execution is out of scope without explicit user authorization on trusted code.
Safety and Side Effects
- Untrusted tarballs and sources:
readTarballSnapshotandstaticAuditPackedTarballdecompress the complete archive into memory without production-grade resource bounds and are strictly limited to trusted synthetic fixtures; never use them on untrusted tarballs. For untrusted.tgzinspection, use a maintained, bounded, non-extracting archive reader configured with explicit compressed/decompressed size limits, member-size and entry-count limits, and rejection of traversal paths, symlinks, and hardlinks (a maintained parser does not automatically enforce bounds unless configured). Never package, install,import(),require(), or run TypeScript compilation on untrusted sources or packages. - Lifecycle scripts boundary (
--ignore-scripts): Passing--ignore-scriptsdisables npm lifecycle hooks (preinstall/install/postinstall,prepack/prepare/postpack) only; it is not a sandbox or sufficient protection for arbitrary untrusted source packaging, build-tool plugins, or top-level code execution duringimport()/require(). - No publishing or private leakage: Never execute
npm publish, push packages to a registry, or copy private package contents into public reports or shared logs. Keep all verification artifacts in temporary directories outside the repository.
Sources and related skills
- Node.js Packages documentation — Package entry points and Conditional exports
- TypeScript Handbook — Modules &
exportsresolution (node16/nodenext) - Related skills: npm-supply-chain-check, effect-smol-package-development, pre-release-review, javascript-typescript-typescript-scaffold, turborepo-caching, vercel-vgpu.