Package Exports

Automatic package.json exports

Package Exports

Packem treats your package.json#exports map as the source of truth for what your package ships. It reads the exports field to infer build entries, and it validates the field against the Node.js specification after building.

Packem derives entries from the exports you declare — you describe the public surface of your package in package.json, and Packem figures out which source files map to each entry.

Entry inference from exports

During entry inference, Packem walks the exports map (via extractExportFilenames) and pairs each declared output path with a matching source file. Conditional keys such as import, require, and types, plus subpath patterns (e.g. "./*"), are all understood. A package.json like this:

{
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    },
    "./utils": {
      "import": "./dist/utils.mjs",
      "require": "./dist/utils.cjs"
    }
  }
}

tells Packem to build two entries (index and utils) and to emit ESM, CJS, and declaration output for them.

Validating exports

After the build, Packem validates the exports field according to the Node.js packages specification (conditional exports, subpath exports, and the exports sugar form). You can toggle this through the validation options:

import { defineConfig } from '@visulima/packem/config'

export default defineConfig({
  validation: {
    packageJson: {
      exports: true, // set to false to skip exports validation
    },
  },
})

Two adjacent options shape how entry inference and validation treat the exports map. Each has its own dedicated page:

  • ignoreExportKeys — an array of export keys to skip during entry inference, useful for excluding keys that only point at images or other non-JavaScript assets, e.g. ["images", "assets", "icons"]. See Ignore Export Keys.
  • validation.packageJson.allowedExportExtensions — extra file extensions to treat as valid inside the exports field during validation. See Allowed Export Extensions.

You can also widen the set of accepted conditional-export keys during validation with validation.packageJson.extraConditions (e.g. ["custom", "my-bundler"]).


Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues