reaction-component-library icon indicating copy to clipboard operation
reaction-component-library copied to clipboard

Do not use .mjs extension for ES module files

Open aldeed opened this issue 5 years ago • 4 comments

Type: minor

Describe the bug When a Webpack app imports this package and styled-components, two copies of the styled-components code are bundled. See Webpack issue: https://github.com/webpack/webpack/issues/9329

Expected behavior Only one copy of styled-components package should be bundled.

Solution This still seems like something wrong in Webpack, but as discovered in the issue, the problem stems from the .mjs extension, which we need not use to provide ES modules. So the solution is to update this file in a few places to use .esm.js instead of .mjs as the extension.

aldeed avatar Jul 12 '19 14:07 aldeed

@willopez I think if you do this and publish updated package, you will then be able to remove your other resolve workaround in the apps that had this issue.

aldeed avatar Jul 12 '19 14:07 aldeed

This is a major issue for me, as the two styled-components modules seem to be interfering with each other and they end up breaking either the reaction components style or the style of my "handmade" components.

EDIT: I "fixed" it adding an alias for styled-components in webpack to force it to chose just one version of it.

Kiailandi avatar Jan 20 '20 09:01 Kiailandi

Would you mind sharing your solution for future troubleshooting @Kiailandi ?

HarisSpahijaPon avatar Feb 14 '20 10:02 HarisSpahijaPon

I added an alias for styled-components in my webpack config file forcing the choice on the one coming from the styled-components package itself.

resolve: { extensions: ['.mjs', '.js', '.jsx', '.tsx', '.ts'], alias: { 'styled-components': 'styled-components/dist/styled-components.browser.esm.js', } }

EDIT: sorry about the format, I don't really understand why it removes the line breaks even if it's formatted as code.

Kiailandi avatar Feb 14 '20 11:02 Kiailandi