Skip to content

feat: switch prettier-plugin-glsl output to ESM#45

Merged
NaridaL merged 1 commit into
mainfrom
esm-output
May 14, 2026
Merged

feat: switch prettier-plugin-glsl output to ESM#45
NaridaL merged 1 commit into
mainfrom
esm-output

Conversation

@NaridaL
Copy link
Copy Markdown
Owner

@NaridaL NaridaL commented May 14, 2026

Fixes #44

Problem

When prettier-plugin-glsl (CJS) is loaded alongside another ESM plugin that also imports chevrotain (e.g. prettier-plugin-wgsl), Node throws:

Cannot require() ES Module .../chevrotain/lib/src/api.js because it is not yet fully loaded.
This may be caused by a race condition if the module is simultaneously dynamically import()-ed via Promise.all().

This happens because Prettier loads all plugins concurrently via Promise.all, and chevrotain v12+ is ESM-only. When one plugin import()s chevrotain and another require()s it simultaneously, Node hits a race condition.

Solution

Switch the rollup output format from CommonJS to ESM:

  • rollup.config.mjs: format: "commonjs"format: "es"
  • package.json: "type": "module", exports path updated to .es.js
  • babel.config.jsbabel.config.cjs (uses module.exports)
  • jest.config.jsjest.config.cjs (uses module.exports)
  • tsconfig.json: updated include for renamed babel config

This is safe for all current Node LTS versions — ESM has been stable (unflagged) since Node 14+, and the package already requires >=22.0.0. Prettier 3.x natively supports ESM plugins.

Testing

  • All existing tests pass (59 passed, 9 skipped)
  • Added an integration test (test-esm-compat/) that reproduces the exact issue scenario: loading prettier-plugin-glsl alongside a fake ESM chevrotain-based plugin via Promise.all, then formatting a GLSL file. This passes cleanly with the ESM output.

@NaridaL NaridaL force-pushed the esm-output branch 2 times, most recently from b66e226 to 09c660e Compare May 14, 2026 11:10
Fixes #44 - ESM chevrotain import error when combined with another plugin.

- Change rollup output format from commonjs to es
- Set package.json type to module
- Update exports path to .es.js
- Rename babel.config.js and jest.config.js to .cjs (they use module.exports)
@NaridaL NaridaL merged commit c130f12 into main May 14, 2026
2 checks passed
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.

ESM chevrotain import error when combined with another plugin

1 participant