clsx: mjs causes trouble
Webpack has an opinion to not resolve mjs from non mjs packages. https://github.com/reactjs/react-transition-group/pull/77#issuecomment-453878611
However you enforced it via module field and webpack becomes crazy about it.
We got this issue https://github.com/dmtrKovalenko/material-ui-pickers/issues/894
I propose to get rid from mjs in favour of just stable module field which can be safely resolved by webpack.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
Just wrapped it up into a plugin:
webpack-modules. Importing it will fix.mjsusage in webpack.Webpack needs this config to make
.mjswork:This tells webpack to treat it like everything else.
I’m not sure why webpack has done this. It’s frustrating tbh. I would much rather use
.mjsbut the reality is that 90% of developers won’t have webpack configured correctly, especially with tools like CRA refusing to include the above config.@TrySound you point the issue with webpack, that should be addressed by
clsx. Version1.0.3breaks my case. I don’t use webpack, and don’t want to run node with-r esm..mjsworks in node and browser without any transpilation. Parcel supports.mjs. I’d say, webpack should follow the node regarding.mjsresolution, because the extension is introduced because of node.Could you point why webpack decided to change the resolution algorithm from node?
Agreed we don’t need
esmsince node supports ESM quite well. But the file should be.mjs. Otherwise, it can’t useexport defaultwhen referred directly from the node. I think https://github.com/developit/htm is a good example of the module supporting ESM. According to https://medium.com/@giltayar/native-es-modules-in-nodejs-status-and-future-directions-part-i-ee5ea3001f71.mjsis the only way to use ESM, and .js reserved for CJS modules, whichdist/clsx.m.jsis not.It was stable – webpack changed their behavior/treatment. IIRC it was masked in CRA uproar, but CRA changed their behavior only because webpack did.
Ideally we wouldn’t need
esmanywhere. For me, it’s a last resort. I mostly use it for unit testing in large codebases.Heh. I like
.esm.jsending and use it in a lot of projects. What do you think?