fix: allow import from CommonJS#453
Conversation
The `exports` field in each of our ESLint config packages used an `import` condition with no `require` or `default` condition alongside it, which broke compatbility with CommonJS. The condition has been removed. This has no impact on ESM modules, but it allows import from CommonJS modules.
Mrtenz
left a comment
There was a problem hiding this comment.
This was intentional (so don't think it's really a "fix"), but I guess changing this makes sense now that importing ESM in CJS is possible.
|
Since when is importing ESM in CJS possible? Wondering if this change would force us to bump the minimum Node version for this repo. |
|
I'd still consider it a fix even if this would have failed in the past, because we're using a condition with no default. i.e. it was failing due to our choice in conditions, not because of an inability to import ESM from CJS (we introduced another error). |
|
To elaborate further, from the Node.js docs: https://nodejs.org/api/packages.html#conditional-exports
|
Node.js 20.19 and 22.x, but the Node version in this repository should not matter either way. |
Changelogs have been updated for #453 (I forgot to update them in the PR).
Changelogs have been updated for #453 (I forgot to update them in the PR). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Changelog-only follow-up with no behavioral or dependency changes. > > **Overview** > Adds **Unreleased** changelog entries across the monorepo packages (`base`, `browser`, `commonjs`, `jest`, `mocha`, `nodejs`, `typescript`, `vitest`) for the fix shipped in [#453](#453): **Allow import from CommonJS**. > > `packages/base` gets a new **Fixed** section under `[Unreleased]`; the other packages add the same bullet under **Fixed**. `packages/typescript` appends the entry to its existing **Fixed** section rather than creating a new one. > > No runtime or config code changes—documentation only, catching up release notes that were omitted when #453 merged. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 27b5540. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This is a release candidate for v15.0.1, a backport release for v15.x <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Packaging-only change with no lint rule or runtime logic edits; risk is limited to module resolution behavior for consumers on 15.0.0. > > **Overview** > **v15.0.1** is a patch backport across all `@metamask/eslint-config*` workspace packages (root and eight published configs). > > The functional change is in each package’s **`exports`** map: the entry point no longer uses an **`import`-only** nested condition. **`types`** and **`default`** now sit directly on `"."`, so Node can resolve the published **`index.mjs`** for consumers that load the package from **CommonJS** (e.g. legacy `eslint.config.js` or tooling that `require`s the config), addressing [#453](#453). > > Versions move **15.0.0 → 15.0.1**; changelogs record the fix under **[15.0.1] [BACKPORT]** with updated compare links. No ESLint rule or source config changes are in this diff. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a3ad788. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
The
exportsfield in each of our ESLint config packages used animportcondition with norequireordefaultcondition alongside it, which broke compatbility with CommonJS. The condition has been removed.This has no impact on ESM modules, but it allows import from CommonJS modules.
Note
Low Risk
Packaging-only
exportsmap change with identical entry file paths; low risk aside from verifying CJS and ESM consumers still resolve types and the main entry.Overview
Fixes CommonJS consumers (e.g.
require('@metamask/eslint-config')or CJS ESLint configs) that could not resolve these packages becausepackage.jsonexports["."]only defined animportcondition.Across all eight published config packages (
base,browser,commonjs,jest,mocha,nodejs,typescript,vitest), the export map is flattened sotypesanddefaultsit directly under"."instead of underimport. Resolution still points at the same./src/index.mjsand./src/index.d.mtsfiles; ESMimportbehavior is unchanged, whiledefaultcan be used when the resolver does not apply theimportcondition.Reviewed by Cursor Bugbot for commit 00f5812. Bugbot is set up for automated code reviews on this repo. Configure here.