Test npm package exports by installing the actual .tgz in a fresh consumer directory and loading it by package name. For a coding-agent patch that changes exports, files, or the build output, require both the archive inventory and a passing consumer probe. A checkout can still contain a compiled file that npm leaves out of the tarball. The install can succeed even when a public entry point leads to that missing file.

Last reviewed: 2026-11-22 (UTC, 2026-11-23 in Asia/Shanghai).

Write down the consumer’s import paths

Before asking an agent to change a package, list the public specifiers a downstream application uses. In the example below, fixture-labels exposes a root import and a fixture-labels/format subpath. The subpath chooses one file for import and another for require. The package also ships an internal file without a public specifier. See the sections on package entry points and module format in the Node.js package documentation .

For each public specifier, record the supported loader, the intended archive path, and one observable result. For the format subpath, the archive needs both package/dist/format.js and package/dist/format.cjs. Both implementations should turn demo into [demo]. Recording the expected branch matters here because the same output from both files could hide an accidental change to the export map.

Ask the agent to report additions and removals to the public specifier list alongside the code diff. A change from fixture-labels/format to fixture-labels/format.js can require a downstream import edit even if the function itself is unchanged. Keep the expected specifiers in the consumer test so a proposed manifest change can be checked against the previous contract. If the patch intentionally changes a public path, include the compatibility decision with the review evidence.

Pack the library and install its tarball

Use a fresh Bash shell with Node.js, npm, mktemp, and tar, and run the shell blocks in order. The fixture uses prebuilt files and has no dependencies. The first block creates a fictional package, saves npm’s JSON packaging report, and lists the archive entries. With no package argument, npm pack packs the current package folder. Use --pack-destination to keep the output outside the library, as documented in the npm pack reference .

set -eu

demo=$(mktemp -d)
mkdir -p "$demo/library/dist" "$demo/artifacts" "$demo/consumer"
cd "$demo/library"

cat > package.json <<'JSON'
{
  "name": "fixture-labels",
  "version": "1.0.0",
  "type": "module",
  "files": ["dist"],
  "exports": {
    ".": "./dist/index.js",
    "./format": {
      "import": "./dist/format.js",
      "require": "./dist/format.cjs"
    }
  }
}
JSON

printf '%s\n' 'export const label = "root";' > dist/index.js
printf '%s\n' 'export const format = (value) => `[${value}]`;' > dist/format.js
printf '%s\n' 'exports.format = (value) => `[${value}]`;' > dist/format.cjs
printf '%s\n' 'export const marker = "internal";' > dist/internal.js

npm pack --ignore-scripts --json --pack-destination "$demo/artifacts" > "$demo/artifacts/pack.json"
archive="$demo/artifacts/fixture-labels-1.0.0.tgz"
tar -tzf "$archive"

cd "$demo/consumer"
printf '%s\n' '{"name":"fixture-consumer","private":true}' > package.json
npm install --offline --ignore-scripts --no-audit --no-fund --no-package-lock "$archive"

Expect five archive entries. They are package/package.json and the four files under package/dist/. Listing dist in files includes the four fixture files together. If a target is missing, compare the archive inventory with the build output and the file selection rules in the npm package.json reference .

Keep the consumer directory outside the source checkout and any workspace dependency tree. This forces the probe to load the installed copy by package name. The install strips the enclosing archive directory, so package/dist/format.cjs becomes dist/format.cjs under the installed package. See the local tarball and ignore-scripts entries in the npm install reference .

Load both branches from the installed package

Save the following as check.mjs in the consumer directory. Call each branch of the format subpath to exercise module loading and check the result. The path assertions catch a switch between branches even when both calls return the expected string. The probe checks that the internal file exists, then expects the unexported specifier to produce ERR_PACKAGE_PATH_NOT_EXPORTED, the error described in the Node.js package documentation .

import assert from "node:assert/strict";
import { existsSync } from "node:fs";
import { createRequire } from "node:module";
import { label } from "fixture-labels";
import { format } from "fixture-labels/format";

const require = createRequire(import.meta.url);
assert.equal(label, "root");
assert.equal(format("demo"), "[demo]");
assert.match(import.meta.resolve("fixture-labels/format"), /\/dist\/format\.js$/);
assert.match(require.resolve("fixture-labels/format"), /[\\/]dist[\\/]format\.cjs$/);
assert.equal(require("fixture-labels/format").format("demo"), "[demo]");

const internal = new URL("./node_modules/fixture-labels/dist/internal.js", import.meta.url);
assert.ok(existsSync(internal));
await assert.rejects(import("fixture-labels/dist/internal.js"), {
  code: "ERR_PACKAGE_PATH_NOT_EXPORTED"
});
console.log("packed exports verified");
node check.mjs

On Node.js v24.22.1 with npm 11.19.1, the local fixture installed one package, printed packed exports verified, and exited with status 0. The root check covers the ESM import. For a real package, extend the probe to every supported combination of entry point and loader, and run it across the versions of Node.js the library supports. Test any promised browser or bundler resolution using that consumer separately.

Reproduce a successful install with a missing entry point

In the disposable library, narrow the files list to omit dist/format.cjs while leaving the file on disk and the export map intact. Pack into a different directory and install in a second fresh consumer so the first install’s files cannot satisfy the probe.

mkdir "$demo/incomplete" "$demo/incomplete-consumer"
cd "$demo/library"
npm pkg set 'files=["dist/index.js","dist/format.js","dist/internal.js"]' --json
npm pack --ignore-scripts --pack-destination "$demo/incomplete"

cd "$demo/incomplete-consumer"
cp "$demo/consumer/check.mjs" .
printf '%s\n' '{"name":"fixture-consumer","private":true}' > package.json
npm install --offline --ignore-scripts --no-audit --no-fund --no-package-lock \
  "$demo/incomplete/fixture-labels-1.0.0.tgz"
probe_status=0
node check.mjs || probe_status=$?
printf 'Incomplete archive probe exit status: %s\n' "$probe_status"
test "$probe_status" -ne 0

In that second run, npm again installed one package. The root and ESM assertions completed, then require.resolve() reported MODULE_NOT_FOUND for dist/format.cjs and the probe exited with status 1. The file still existed in the library’s dist directory. That result isolates the packaging change from the build and confirms that the probe catches a missing branch.

What the consumer showsWhat to inspect in the patch
An exported target is absent from the tarballIf the file exists before packing, inspect files and applicable ignore rules. If the build never produced it, inspect the build inputs and outputs.
The import works but resolves to the wrong fileCheck the matching conditions and their order in exports. An earlier condition that applies to the loader can select a different file.
A promised subpath throws ERR_PACKAGE_PATH_NOT_EXPORTEDCompare the exact specifier, including any extension, with the keys in exports.
The target ships but will not loadCheck its extension and the nearest package.json for the expected module format. Then check the first failing import inside the target.
Both paths are present but only one call returns the expected valueCheck the built implementation for that branch and parity between the module formats.

Make the tarball the review artifact

Run the real package’s release build and packaging command on the revision under review, including any approved build hooks needed to produce its files. Record the Node and npm versions, the archive filename and SHA-256 digest, and the consumer outcomes for each specifier. If runtime dependencies are needed, provision them through the consumer’s normal approved resolution policy. The offline setup above serves the dependency-free fixture. Exercise any install-time generation that your library promises using the reviewed install configuration as well.

Keep the probed archive available to the release job. A second pack after the probe can pick up a different generated file or a changed ignore rule. If the release workflow creates a new artifact, repeat the consumer probe on it. If the package build itself depends on local state, start with the guide to hermetic builds .

For the next agent patch touching packaging, pick the busiest public subpath and add a check from both promised loaders. Compare the base and proposed tarballs under the same runtime and keep the probes with the package. Include the archive identity, changed specifiers, and any explicitly approved compatibility change in the pull request review handoff .

Sources checked

These official references were checked on November 22, 2026 UTC. They describe evergreen packaging and resolution behavior. The fixture results come from the local run on the versions listed above.