Skip to content

Use exports for the default path when main is missing - #404

Merged
ai merged 1 commit into
ai:mainfrom
wahidrizka:default-path-from-exports
Sep 28, 2026
Merged

ai merged 1 commit into
ai:mainfrom
wahidrizka:default-path-from-exports

Conversation

@wahidrizka

Copy link
Copy Markdown
Contributor

Fixes #285.

Without path in a check, Size Limit takes the file from main in package.json and falls back to index.js. A package that only has exports, as in #285, has neither:

{
  "type": "module",
  "exports": {
    ".": {
      "import": "./lib/index.js"
    }
  }
}

With Size Limit 14.1.0 this crashes with ENOENT: no such file or directory, open '.../index.js'.

Now, when there is no main, the root entry of exports is used before falling back to index.js: the field itself when it is a string, otherwise the . entry, with conditions resolved in import, default, require order (nested conditions like import: { types, default } included). main still wins when it is set, so existing configs keep their files.

The new test uses the package.json from #285 as a fixture and fails without the change. oxlint passes. Locally on Windows, 6 other tests in packages/size-limit fail with and without this change (the same 6, for example the path separator in "takes config from CLI config argument").

Without `path` in the config, Size Limit took `main` from package.json
and otherwise `index.js`. An ESM-only package with only `exports`, like
the one in ai#285, crashed with ENOENT on the missing `index.js`. Take the
root entry of `exports` before falling back to `index.js`, preferring
the `import` condition.
@ai
ai merged commit f6827f7 into ai:main Sep 28, 2026
3 checks passed
@ai

ai commented Sep 28, 2026

Copy link
Copy Markdown
Owner

If nobody needs it ASAP I will release it with next feature. Size Limit releases are a little bit painful.

@ai

ai commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Released in 14.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support NodeJS ESM Module only project

2 participants