← LeaderboardThe Skill Leaderboard

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.

Published by sickn33 ↗sickn33/agentic-awesome-skills

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-check vets one public npm package for malware, CVEs, publisher changes, and typosquatting before installation without packing or validating consumer module resolution.
  • effect-smol-package-development manages Effect v4 monorepo workspace registration, barrels, and changesets inside an Effect workspace.
  • pre-release-review audits git diffs for general production deploy readiness (migrations, secrets, rollout order).
  • javascript-typescript-typescript-scaffold, turborepo-caching, and vercel-vgpu cover 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" in package.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) and npm CLI (npm-cli.js for trusted source packing and --offline --ignore-scripts installation).
  • 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's readTarballSnapshot or staticAuditPackedTarball helpers 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 run tsc on untrusted source directories. Do not present npm pack --ignore-scripts or npm install --ignore-scripts as a sandbox or sufficient protection for arbitrary untrusted source packaging or module execution (--ignore-scripts skips npm lifecycle hooks only, not build plugins or code evaluation).
    • Runtime consumer checks (import, require, tsc): Require trusted, authorized packages or synthetic reproductions.
  • 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:

  1. Read package/package.json and the member file list directly from the target .tgz archive without extracting files or following symlinks (use an explicitly bounded, maintained, non-extracting reader on untrusted .tgz files; limit readTarballSnapshot / staticAuditPackedTarball strictly to trusted synthetic fixtures). Source directories often drift from already-built .tgz artifacts, and build tooling can rewrite publishConfig.exports or workspace:* ranges during packing.
  2. Synthetic-fixture exports inspection & authoritative runtime checks: In trusted synthetic fixtures, collectExportLeaves / staticAuditPackedTarball inspect literal exports targets against tarball members, check "types" before runtime conditions and "default" last at each nesting object level, check wildcard patterns (*), and record null exclusions. For fallback arrays, collectExportLeaves uses 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, and missingRequired / missingFallback are fixture inspection results rather than authoritative general resolver classifications. Keep real installed-consumer runtime checks (for example confirming ["./missing.cjs", "./present.cjs"] fails CommonJS require with MODULE_NOT_FOUND even when ./present.cjs exists) as authoritative for the specific cases they exercise.
  3. Manual manifest checklist (separate from exports harness): verify main, module, top-level types, bin, and dependencies for unresolved workspace:* or catalog: ranges inside the packed package/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:

  1. On trusted, authorized local source only, build the target .tgz artifact (npm pack --ignore-scripts --pack-destination <tmp>) or audit an existing trusted tarball.
  2. Create isolated temporary consumer directories outside the monorepo workspace with NODE_PATH and NODE_OPTIONS cleared so workspace symlinks, root node_modules, and tsconfig.json paths cannot mask missing files.
  3. Install the .tgz offline with lifecycle scripts disabled (npm install --offline --ignore-scripts --no-audit --no-fund <tarball.tgz>).
  4. Execute separate ESM (import), CommonJS (require), and TypeScript (tsc --noEmit with "moduleResolution": "nodenext") checks by passing explicit argument vectors to process.execPath (shell: false; never build unquoted cmd.exe shell strings).
  5. Assert actual exported runtime values, TypeScript diagnostics + line/column locations, and blocked subpath errors unconditionally — do not treat process exit 0 alone as sufficient, and do not skip failing type checks. Note that Node.js 20.19+ / 22.12+ / 24 supports synchronous require(esm) for eligible ES modules without top-level await (top-level await throws ERR_REQUIRE_ASYNC_MODULE, while older Node releases throw ERR_REQUIRE_ESM), so verify the resolved target path and module format explicitly when CommonJS consumers need a .cjs entry 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 .tgz SHA-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 null subpaths), 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: readTarballSnapshot and staticAuditPackedTarball decompress 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 .tgz inspection, 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-scripts disables 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 during import()/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

npm-package-exports-audit by sickn33 · The Skill Leaderboard