Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sjmik opened this issue Aug 13, 2019 · 4 comments
Open

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

sjmik opened this issue Aug 13, 2019 · 4 comments

Comments

@sjmik
Copy link

sjmik commented Aug 13, 2019

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';.

webpack/webpack#5756

@fuzetsu
Copy link
Owner

fuzetsu commented Aug 14, 2019

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
Copy link
Author

sjmik commented Aug 14, 2019

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
Copy link
Owner

fuzetsu commented Aug 14, 2019

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
Copy link
Author

sjmik commented Aug 14, 2019

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

  • Change import merge from 'mergerino' to import merge from 'mergerino/dist/mergerino.es5'
  • Or, add resolve: { mainFields: ['browser', 'main', 'module'] } to webpack.config.js
  • Or, add "browser": "dist/mergerino.es5.min.js" to node_modules\mergerino\package.json

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants