Skip to content

Webpack not prioritizing the pkg.module for dependencies #5673

Closed
@jshcrowthe

Description

@jshcrowthe

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Webpack prioritizes the browser field in a package.json, over the module field (if both are passed)

See:

this.set("resolve.mainFields", "make", (options) => {
if(options.target === "web" || options.target === "webworker")
return ["browser", "module", "main"];
else
return ["module", "main"];
});

If the current behavior is a bug, please provide the steps to reproduce.

Created two gists, a module and a consumer. They are available here:

Repro Steps:

  1. git clone https://gist.github.com/jshcrowthe/64ec07274e4ac966b3e116078c586dfa
  2. cd 64ec07274e4ac966b3e116078c586dfa
  3. npm install
  4. npm start
  5. Open browser and navigate to webpack-dev-server URL
  6. Observe console logs, should look something like the following:

screen shot 2017-09-13 at 12 01 58 pm

What is the expected behavior?

Webpack should prioritize the pkg.module field over pkg.browser. Browserify also relies on the pkg.browser but does not have support for ES Modules. Seeing as webpack is able to more intelligently parse the ES Module bundles, it should prioritize that bundle if available.

NOTE: I am aware that you can change the resolve.mainFields to modify this however you'd like. I'm suggesting that the default behavior should be changed

If this is a feature request, what is motivation or use case for changing the behavior?

n/a

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

  • Webpack: 3.5.6
  • Node.js: 8.4.0
  • NPM: 5.4.1
  • Yarn: 1.0.1
  • OS: macOS 10.12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions