salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 393 forks source link

Support transforming `.mjs` files #3474

Open wes-goulet opened 1 year ago

wes-goulet commented 1 year ago

Is your feature request related to a problem? Please describe. More and more libraries are leveraging the .mjs file extension for their ES Modules. The LWC transformer code only looks for .js or .ts to transform. It throws an error if .mjs is used:

CompilerError: LWC1005: No available transformer for "~/my-project/node_modules/SomeDep/dist/foo.mjs"

Notice this is for a dependency in node_modules that I (as the LWC component/app author) might not have control over. So the current workaround of renaming the file to .js will not work here, I don't have control over the dependency.

Describe the solution you'd like Support the .mjs file extension when LWC transforms files.

Update https://github.com/salesforce/lwc/blob/master/packages/@lwc/compiler/src/transformers/transformer.ts#L86 to this:

case '.ts':
case '.js':
case '.mjs':
    transformer = scriptTransformer;
    break;

Describe alternatives you've considered Don't use dependencies that use .mjs 😞

Additional context Node docs and v8 docs recommend using the .mjs extension and I see more and more libraries moving that direction (thankfully, it's the ~future~ present).

nolanlawson commented 1 year ago

Thanks for opening the issue. FWIW there are multiple places this would also have to be changed:

wjhsf commented 5 months ago

4261 added support for .mjs to @lwc/compiler and @lwc/rollup-plugin.