Skip to content
package.json checker

package.json exports Resolver

Paste the `exports` of a package.json to see **which file** `import 'pkg'` or `import 'pkg/feature'` resolves to, for Node.js import / require, bundlers and TypeScript.
It shows the matched key, the conditions followed (import → default…) and the part matched by a `*` pattern. Without `exports`, it looks at `main`, `module` and `types`.
It also checks the writing: `types` after other conditions, `default` not last, `require` pointing at `.mjs`, and `./package.json` not exported. Everything is processed in your browser and never sent to a server.

Everything is processed in your browser and never sent to a server.

Result

These are typical sets of conditions. Real tools may use others too, such as development, production, style or worker. default is always used.

All subpaths × conditions

Each key of `exports` and each key of `imports` (internal paths starting with `#`) resolved for every set of conditions. For a pattern (`*`) key, the `*` is replaced with `x` to try it.

Things worth a look

A mechanical check of how it is written. A finding may be what you intended.

Guide

How to use & features

  • Paste the contents of your package.json, including `exports`, into the box. A sample is loaded at first.
  • Enter "." for `import 'pkg'` or "./feature" for `import 'pkg/feature'`, and pick Node.js (import / require), a bundler or TypeScript in "Conditions". "Custom" lets you list conditions freely.
  • "Result" shows the file it resolves to, the matched key, the conditions followed (import → default…) and the part matched by a `*` pattern. If it cannot resolve, the reason is shown.
  • "All subpaths × conditions" lists every key of `exports` resolved for every set of conditions.
  • "Things worth a look" shows the order of `types`, the position of `default`, `require` pointing at `.mjs`, a missing `./package.json` and more.
FAQ

FAQ

  • In what order are `exports` resolved?

    It follows the Node.js algorithm. It first looks for a key that exactly matches the subpath; if there is none, it tries the `*` pattern keys, most specific (longest base) first. If the value of the key is an object of conditions, it picks the first one **in written order** that matches the conditions in use (or `default`). For an array, it skips values it cannot use and takes the next candidate. A `null` value blocks that path.
  • Are `main` and `module` used when `exports` exists?

    When `exports` exists, Node.js (12.7 and later) looks only at `exports` and ignores `main`. Node.js itself does not read `module` (bundlers may). Only when there is no `exports` does it look for an entry in `main` (or `index.js`), `module`, `browser` and `types`. This tool shows that entry when `exports` is missing.
  • Are the condition sets the same as in real tools?

    They are typical sets. Node.js uses `node` and `import` / `require`, TypeScript uses `types` with `import` / `require`, and bundlers use `import`, `module` and `browser`. Real tools also have their own conditions such as `development`, `production`, `style` and `worker`. Use "Custom" to list the conditions and check.
  • Is my package.json sent to a server?

    No. Everything is processed in your browser and nothing is sent to a server.
  • Why is `types` after `import` a problem?

    TypeScript reads the conditions from the top and uses the first that matches. If `import` comes first, resolution stops there and never reaches `types` below it. Put `types` first.
Use cases

Common use cases

  • Check "is this path exported?"

    See whether `import 'pkg/internal/foo'` works or fails with `ERR_PACKAGE_PATH_NOT_EXPORTED`, without running anything. Blocking by patterns (`*`) and `null` shows up in the result too.
  • Design a dual ESM / CJS package

    See side by side which files `import` and `require` resolve to. It also checks the dual package pitfalls when they point at different files.
  • Find why TypeScript cannot find the types

    Notice the position of `types`, or that no type definitions are specified. You can also see which file TypeScript's conditions select.
  • Do a final check before publishing a library

    The table of all subpaths × conditions lets you check for unintended blocking, or `require` pointing at an `.mjs` file, before you publish.
Notes

Notes & limitations

  • It does not match every real tool exactly

    It follows the Node.js algorithm, but bundlers and TypeScript can use their own conditions, extension completion and `typesVersions`. Check with the real tool in the end.
  • `typesVersions` is not handled

    The tool looks only at `exports` (`imports` for paths starting with `#`) and, when `exports` is missing, `main`, `module`, `browser` and `types`.
  • It does not check that files exist

    It only shows the resolved path. Whether the file exists or loads is not checked.

Articles for this tool

Recent Articles