lukeed/clsxPublic

A tiny (239B) utility for constructing `className` strings conditionally.

mjs causes trouble

TR

TrySound opened ยท

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.

  1. LU

    Wow, what a nightmare. I swear they keep changing their resolution alg & how they treat ESM & `.mjs` files ๐Ÿ˜ 

  2. lukeedclosed 29b2fcea29e27 years ago on GitHub

  3. TR
    Author

    Heh. I like `.esm.js` ending and use it in a lot of projects. What do you think?

  4. TR
    Author

    Thanks for fast feedback!

  5. LU

    Had that initially โ€“ making a (lame attempt) statement for `.mjs` support.

    Thanks for raising the issue ๐Ÿ™‡

  6. TR
    Author

    I would wait til mjs will become stable. Ideally we should all move to https://github.com/standard-things/esm

  7. LU

    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 `esm` anywhere. For me, it's a last resort. I mostly use it for unit testing in large codebases.

  8. DM

    Please, let me know when it will be published

  9. LU

    @dmtrKovalenko It already is :) version 1.0.3

  10. dmtrKovalenkomentioned7 years ago on GitHub

  11. dmtrKovalenkosubscribed7 years ago on GitHub

  12. AL

    Agreed we don't need `esm` since node supports ESM quite well. But the file should be `.mjs`. Otherwise, it can't use `export default` when 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 `.mjs` is the only way to use ESM, and .js reserved for CJS modules, which `dist/clsx.m.js` is not.

  13. TR
    Author

    @alekseykulikov `.mjs` doesn't work. Webpack is broken with it in many cases. [esm](https://github.com/standard-things/esm) is a better option. It supports `module` field just fine.

    @lukeed esm allows to not transpile commonjs to esm in pure module bundler like rollup.

  14. alekseykulikovmentioned7 years ago on GitHub

  15. alekseykulikovsubscribed7 years ago on GitHub

  16. lukeedmentioned7 years ago on GitHub

  17. lukeedsubscribed7 years ago on GitHub

  18. TR
    Author

    @alekseykulikov clsx had the same setup as htm has. Try to tell everybody it's their problem. https://github.com/dmtrKovalenko/material-ui-pickers/issues/894

    I'd say mjs is not ready for use.

  19. alekseykulikovmentioned7 years ago on GitHub

  20. alekseykulikovsubscribed7 years ago on GitHub

  21. AL

    @TrySound you point the issue with webpack, that should be addressed by `clsx`. Version `1.0.3` breaks my case. I don't use webpack, and don't want to run node with `-r esm`. `.mjs` works in node and browser without any transpilation. Parcel supports `.mjs`. I'd say, webpack should follow the node regarding `.mjs` resolution, because the extension is introduced because of node.

    Could you point why webpack decided to change the resolution algorithm from node?

  22. TrySoundmentioned7 years ago on GitHub

  23. TrySoundsubscribed7 years ago on GitHub

  24. LU

    Webpack needs this config to make `.mjs` work:

    ```js rules: [{ test: /\.m?jsx?$/, type: 'javascript/auto', }] ```

    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 `.mjs` but the reality is that 90% of developers won't have webpack configured correctly, especially with tools like CRA refusing to include the above config.

  25. TR
    Author

    @alekseykulikov But you have to add experimental-modules flag. Is it shorter? And you have to use ugly mjs extension. It's made mostly for dual mode which fails with webpack. That's why I would wait until it become stable.

  26. alekseykulikovmentioned7 years ago on GitHub

  27. alekseykulikovsubscribed7 years ago on GitHub

  28. LU

    Just wrapped it up into a plugin: [`webpack-modules`](https://github.com/lukeed/webpack-modules). Importing it will fix `.mjs` usage in webpack.

  29. lukeedreferenced this in fix: typo module path #97 years ago on GitHub