I am using Webpack 2 beta21 in some setup where I am trying to combine System.import
auto chunks + HMR + SSR React. I am currently struggle with how to use modules in es2015 module syntax (as suggested by module
/jsnext:main
entries). As far as I understand I have to transpile that code. But normally we do not transpile any code from node_modules
, correct? So how can I do that “basic” transpilation that I have a non-module output from all these different sources?
3 thoughts on “ES Modules in node_modules. How to transpile?”
Comments are closed.
Webpack 2 should transpile ES module for you automatically.
jsnext:main
ormodule
code should always already be transpiled. The only difference is that they use ES6 module syntax instead of commonjs function calls.Webpack does not transpile ES6 module syntax to commonjs modules, or even transpile commonjs; what it does is convert code using those respective module systems to use webpack’s module system instead.
If the code pointed to inside the
jsnext:main
/module
entry points needs any kind of transpilation to ES5 (besides, again, the module syntax itself), it is a bug with the module that has an incorrect build published.@wegry don’t use
babel-preset-es2015-native-modules
, use[ "babel-preset-es2015", { "modules": false } ]
.I finally got a node_modules package to compile with
babel-loader
after hours of struggling.The problem was that the package had it’s own
.babelrc
published which was overriding my babel config (which is in my package.json).My solution is to set
babelrc: false
in the loader config and specify the babel config in the loader. However, I read this config from my package.json, so it’s not duplicated.