6 thoughts on “Will/does Webpack support “module” field?

  1. Coming from ReactTraining/react-router#3333, I’d really like if there were a way to specify the location of the ES module build for webpack users.

    I’m a little bit frightened that people are importing from the subdirectory containing the ES modules directly.

  2. Why do you need a plugin for this? Just set e.g.

    mainFields: ['jsnext:main', 'browser', 'main']

    in your webpack config.

  3. In webpack.config.js, just do e.g.

    resolve: {
      mainFields: ['jsnext:main', 'browser', 'main'],

    That’s all you need.

  4. Besides adding 'jsnext:main' to mainFields, don’t you need to somehow teach Babel “you actually need to process some stuff in my node_modules folder”?

  5. Since we are using the Angular CLI which has no transpiling other than Typescript, any modules which specify a module field will be imported as es2015 modules. And a lot of times things will only really break when you run it in an older browser that doesn’t support class, something which you normally don’t do everyday when developing.

    I think we might be conflating two different things here. The module entry point should point to code with ES6 modules but not necessarily other ES6 features. People who want their libraries to be in ESM format can/should still precompile other ES6 features so that older browsers don’t break.

Comments are closed.