Skip to content

feat: explicitly import CJS bundles for LWC @W-21382713#404

Open
wjhsf wants to merge 6 commits intomasterfrom
wjh/lwc-cjs
Open

feat: explicitly import CJS bundles for LWC @W-21382713#404
wjhsf wants to merge 6 commits intomasterfrom
wjh/lwc-cjs

Conversation

@wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Feb 27, 2026

LWC v8 is CJS by default (no type in package.json and main points to dist/index.cjs.js). LWC v9 is ESM by default (type: module and main points to ESM dist/index.js). For compatibility, LWC v9 also provides dist/index.cjs.

In this PR, we change references to @lwc/engine-dom (and friends) to @lwc/engine-dom/dist/index.cjs. Because of node's flexible module resolution algorithm, this resolves to the CJS bundle for both v8 and v9. No further code changes are required to support both v8 and v9. The downside of this approach, however, is that it takes an explicit dependency on the CJS bundle, effectively just kicking the can down the road for the CJS -> ESM switchover.

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.

1 participant