lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Support transforming `.mjs` files

Open wes-goulet opened this issue 2 years ago • 2 comments

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

wes-goulet avatar Apr 27 '23 21:04 wes-goulet

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

  • LWR
  • lwc-test
  • lwc-platform
  • lwc-webpack-plugin

nolanlawson avatar May 02 '23 20:05 nolanlawson

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

wjhsf avatar Jun 10 '24 14:06 wjhsf