fuzetsu / mergerino

immutable merge util for state management
MIT License
71 stars 6 forks source link

Webpack picks up "module" entry point instead of "main" #5

Open sjmik opened 5 years ago

sjmik commented 5 years ago

Hey, I don't know much about authoring node modules, so I'm not sure if there is anything you can do about this. I'm using webpack to run my code through babel to get IE11 support. I have it configured to only babelfy my source code, not node_modules.

If I import mergerino like import merge from 'mergerino'; webpack will pick up the ES6 version. I can workaround it by instead doing import merge from 'mergerino/dist/mergerino.es5';.

https://github.com/webpack/webpack/issues/5756

fuzetsu commented 5 years ago

Thanks for the report.

Removing the module field from the package.json would likely fix it, but then I wouldn't be exposing the module anymore, which I want to do.

I'll have to dig around a little to see if there's some good way to handle it, and fix it if possible or at least document it.

sjmik commented 5 years ago

That issue I read suggested you might be able to add a browser field. But idk... I couldn't even find module in the npm docs.

fuzetsu commented 5 years ago

Did you see this workaround in the comments for that issue?

resolve: { mainFields: ["main", "module"] }

Since you don't want any modules in your bundle it seems logical.

sjmik commented 5 years ago

Heh, I didn't bother looking into it because the import change worked. Anyway, any one of these changes independently fix my issue:

Looks like the webpack default is resolve: { mainFields: ['browser', 'module', 'main'] } (from https://webpack.js.org/configuration/resolve/#resolve-mainfields)

Feel free to close this if you think it's not worth changing.