-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
browser
vs module
fields in package.json
#4674
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
Comments
We may need a field |
Another way to solve it nodejs/node-eps#60. Not advocating this approach, just want to let you know. UPD: there is also esnext prposal. Started to collect all those undocumented package.json fields in small repository |
@alexfedoseev found solution, package should be in this form to work properly with wepback {
"name": "main-module-browser",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"browser": {
"./dist/index.js": "./dist/index.browser.js",
"./dist/index.esm.js": "./dist/index.browser.esm.js"
}
} Full example https://github.com/stereobooster/main-module-browser-test |
Just have similiar problem and happen to found this issue. |
@DrSensor here is full spec https://github.com/defunctzombie/package-browser-field-spec it doesn't specify types of the packages. One thing that matters is if code uses browser-specific (example: Dom) or server-specific (example: filesystem) features. |
To get rid of the problems with using some bundler packages which adopts 'browser' field rather than 'module'. See: webpack/webpack#4674
Does this mean that currently webpack's order of importing is I would also prefer module > browser > main. |
The module landscape is a mess. Currently the UMD build is preferred by Webpack and esbuild, since the `browser` field takes precedence over the `module` field. However, conditional exports (yet another field!) now allow for a separate approach. Setting the first type to `import` results in both bundlers favouring it over the UMD build. I'm leaving Browser around as a legacy field for now. See: - webpack/webpack#4674 - evanw/esbuild#187 - https://webpack.js.org/guides/package-exports/#providing-different-versions-depending-on-target-environment - https://nodejs.org/api/packages.html#packages_exports_sugar
Hi ! I don't get your snippet, how does it work ? It choose randomly ? |
Do you want to request a feature or report a bug?
I don't think it's a bug, but confusing and inefficient behavior.
What is the current behavior?
When module's
package.json
containsbrowser
,module
&main
fields, webpack is bundlingbrowser
build by default.What is the expected behavior?
The key point of the
module
build is to optimize compiled bundle. And even if a package has hq ES build, it's not being used by default in favor of legacy UMD/IIFE builds. So expected behavior is to usemodule
build by default.The text was updated successfully, but these errors were encountered: