Skip to content

fix: allow import from CommonJS#453

Merged
Gudahtt merged 1 commit into
mainfrom
allow-import-from-commonjs
Jul 20, 2026
Merged

fix: allow import from CommonJS#453
Gudahtt merged 1 commit into
mainfrom
allow-import-from-commonjs

Conversation

@Gudahtt

@Gudahtt Gudahtt commented Jul 17, 2026

Copy link
Copy Markdown
Member

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.


Note

Low Risk
Packaging-only exports map 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 because package.json exports["."] only defined an import condition.

Across all eight published config packages (base, browser, commonjs, jest, mocha, nodejs, typescript, vitest), the export map is flattened so types and default sit directly under "." instead of under import. Resolution still points at the same ./src/index.mjs and ./src/index.d.mts files; ESM import behavior is unchanged, while default can be used when the resolver does not apply the import condition.

Reviewed by Cursor Bugbot for commit 00f5812. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
@Gudahtt
Gudahtt marked this pull request as ready for review July 17, 2026 20:16
@Gudahtt
Gudahtt requested a review from a team as a code owner July 17, 2026 20:16

@Mrtenz Mrtenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mcmire

mcmire commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Since when is importing ESM in CJS possible? Wondering if this change would force us to bump the minimum Node version for this repo.

@Gudahtt

Gudahtt commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

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).

@Gudahtt

Gudahtt commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

To elaborate further, from the Node.js docs: https://nodejs.org/api/packages.html#conditional-exports

When using environment branches, always include a "default" condition where possible. Providing a "default" condition ensures that any unknown JS environments are able to use this universal implementation, which helps avoid these JS environments from having to pretend to be existing environments in order to support packages with conditional exports.

@Mrtenz

Mrtenz commented Jul 20, 2026

Copy link
Copy Markdown
Member

Since when is importing ESM in CJS possible? Wondering if this change would force us to bump the minimum Node version for this repo.

Node.js 20.19 and 22.x, but the Node version in this repository should not matter either way.

@Gudahtt
Gudahtt merged commit 4254a6e into main Jul 20, 2026
26 checks passed
@Gudahtt
Gudahtt deleted the allow-import-from-commonjs branch July 20, 2026 13:36
Gudahtt added a commit that referenced this pull request Jul 20, 2026
Changelogs have been updated for #453 (I forgot to update them in the
PR).
Gudahtt added a commit that referenced this pull request Jul 20, 2026
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 -->
@cursor cursor Bot mentioned this pull request Jul 20, 2026
Gudahtt added a commit that referenced this pull request Jul 20, 2026
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 -->
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.

3 participants