Skip to content

Commit bf5aab8

Browse files
fiskertats-u
andauthored
Revert "Use ESM entrypoint for require(ESM)" (#17156)
Co-authored-by: Tatsunori Uchino <[email protected]>
1 parent c98acab commit bf5aab8

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

changelog_unreleased/misc/17156.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### Remove `module-sync` condition (#17156 by @fisker)
2+
3+
In Prettier 3.5.0, [we added `module-sync` condition to `package.json`](https://prettier.io/blog/2025/02/09/3.5.0#use-esm-entrypoint-for-requireesm-16958-by-tats-u), so that `require("prettier")` can use ESM version, but turns out it doesn't work if CommonJS and ESM plugins both imports builtin plugins. To solve this problem, we decide simply remove the `module-sync` condition, so `require("prettier")` will still use the CommonJS version, we'll revisit until `require(ESM)` feature is more stable.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"exports": {
1616
".": {
1717
"types": "./src/index.d.ts",
18-
"module-sync": "./src/index.js",
1918
"require": "./src/index.cjs",
2019
"default": "./src/index.js"
2120
},

scripts/build/build-package-json.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ async function buildPackageJson({ file, files }) {
4242
exports: {
4343
".": {
4444
types: "./index.d.ts",
45-
"module-sync": "./index.mjs",
4645
require: "./index.cjs",
4746
browser: {
4847
import: "./standalone.mjs",
@@ -56,14 +55,14 @@ async function buildPackageJson({ file, files }) {
5655
.filter((file) => file.output.format === "umd")
5756
.map((file) => {
5857
const basename = path.basename(file.output.file, ".js");
59-
const mjsPath = `./${file.output.file.replace(/\.js$/u, ".mjs")}`;
6058
return [
6159
file.isPlugin ? `./plugins/${basename}` : `./${basename}`,
6260
{
6361
types: `./${file.output.file.replace(/\.js$/u, ".d.ts")}`,
64-
"module-sync": mjsPath,
62+
// `module-sync` condition can prevent CJS plugins from working: https://github.com/prettier/prettier/issues/17139
63+
// Perform a test before re-adding it.
6564
require: `./${file.output.file}`,
66-
default: mjsPath,
65+
default: `./${file.output.file.replace(/\.js$/u, ".mjs")}`,
6766
},
6867
];
6968
}),

website/blog/2025-02-09-3.5.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ If you can't upgrade Prettier for some reason, you can still use JSONC syntax in
398398

399399
#### Use ESM entrypoint for `require(ESM)` ([#16958](https://github.com/prettier/prettier/pull/16958) by [@tats-u](https://github.com/tats-u))
400400

401+
:::info
402+
403+
This change has been reverted in v3.5.2, check [#17139](https://github.com/prettier/prettier/pull/17139) for details.
404+
405+
:::
406+
401407
Node.js 22.12 or later [can (experimentally) load ESM modules with `require` function](https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require) without runtime flags. This change enables `require` to load Prettier without the CommonJS entrypoint with almost only the ability to import the ESM entrypoint.
402408

403409
The feature to load ES modules with `require` is not completely stable but can be used without ExperimentalWarning as of Node 22.13.

0 commit comments

Comments
 (0)