package-exports-drift-check reads a package.json exports map and tells you which targets point at files you don't publish. Until today it skipped two kinds of entry. A wildcard target such as "./features/*": "./src/*.js" was "not checked". A target such as "./compat": "other-pkg/compat" was labelled "a bare specifier re-exporting another package, nothing on disk to check".
The second label was wrong, and so was a test that called "../outside.js" a normal file target. Node accepts neither. Every exports target must start with ./:
$ node -e 'require.resolve("q/re")'
ERR_INVALID_PACKAGE_TARGET Invalid "exports" target "other-pkg/sub" defined for './re'
in the package config .../q/package.json; targets must start with "./"
Only imports, the #name map, may point at another package. So the checker had been passing a package.json that fails every import through that subpath.
How we found it
We wanted the tool to answer the question people actually ask: which file does import "my-lib/feature" reach? So we wrote Node's resolution algorithm into resolve.mjs. The steps come from the algorithm in Node's ESM documentation: PACKAGE_EXPORTS_RESOLVE, PACKAGE_IMPORTS_RESOLVE, PATTERN_KEY_COMPARE and PACKAGE_TARGET_RESOLVE. Then we checked it against Node itself.
resolve.diff.test.mjs generates packages from a seed. Each gets random exports and imports maps full of the shapes that go wrong: pattern keys of different specificity, nested conditions, fallback arrays holding invalid items, null blocks, .., node_modules and %2e segments, targets without ./, numeric condition keys, and maps that mix . keys with condition keys. A child node then resolves the same specifiers three ways: ESM import, import with --conditions=development, and CommonJS require. The test compares the file or error code each one returns.
One detail makes ESM a precise oracle: import.meta.resolve returns the URL without opening the file, so nothing has to exist on disk. require does open the file, so for CommonJS we compare the path in its "Cannot find module" message.
On Node 22.23.5 the default seed gives 5,079 resolutions and 0 disagreements. Seeds 1 to 5, at 1,000 packages each, gave between 17,019 and 17,166 resolutions each, also with 0 disagreements. About a fifth of the cases resolve to a file. The rest end in one of Node's five resolution errors, so the error paths get as much testing as the successful ones.
What the disagreements taught us on the way to zero
The first full run disagreed with Node on 272 of 5,079 cases. Some of those were bugs in the test's own generator. Fixing the rest taught us four things about Node 22:
- If
exportsis not a string, array or object (say1ortrue), Node reads it as noexportsat all and falls back tomain. It is not an error. - With no
importsfield,require("#x")looks#xup as an ordinary package name and fails with "Cannot find module".import "#x"throwsERR_PACKAGE_IMPORT_NOT_DEFINEDinstead. - An
importstarget of""is passed on as a package name. #/xis still an invalid specifier in Node 22.
What changed in the tool
- Targets Node refuses are reported as invalid, with the reason. That covers a missing
./, another package's name,../, an absolute path or URL, and a.,..ornode_modulessegment. - Wildcard targets are matched against your file listing, with every
*filled by the same text, as Node does. A pattern that reaches no file is reported. One that does shows an example, such as./utils/format → ./esm/utils/format.js. - A map that mixes
"."keys with condition keys is reported. Node throwsERR_INVALID_PACKAGE_CONFIGon every import of such a package. - A new resolve panel, and
node cli.mjs resolve my-lib/feature --require --conditions=development, show the file that wins and the key, condition and fallback that decided it.
Everything still runs in your browser, and nothing is uploaded. The tool checks what Node does. It is not a bundler, and a bundler adds its own conditions. You can type those conditions into the panel, but test a real install before you rely on any result.
Written with AI assistance. The numbers above come from the test runs recorded in the tool's README.