I want to rewrite an old module of mine to ESNext. To bundle it, I use Rollup, to compile it back, I use Babel, of course. All of this gets ochestrated in Gulp.
All of it went well so far, while upgrading to Babel v7, Gulp v4 and the newest version of rollup (v0.56.0). But now, as I intend to include useBuiltIns: true
in my babel config, so I don't have to worry about polyfilling, I get an error thrown by rollup:
TypeError: Cannot read property 'code' of null
at error (/Users/robin.loeffel/Sites/misc/jz2/node_modules/rollup/dist/rollup.js:168:15)
at Object.error (/Users/robin.loeffel/Sites/misc/jz2/node_modules/rollup/dist/rollup.js:17916:21)
at /Users/robin.loeffel/Sites/misc/jz2/node_modules/rollup/dist/rollup.js:17925:29
at <anonymous>
You can look at my gulpfile here. It's fairly simple. I use rollup-stream
for the integration with gulp and use rollup-plugin-babel
, rollup-plugin-uglify
, rollup-plugin-node-resolve
and rollup-plugin-commonjs
as plugins. Here's an example of how I integrated it, if you don't have the time to look through the whole thing:
gulp.task('make:iife:min', () => {
return rollupStream({
input: config.paths.index,
output: {
format: 'iife',
name: 'jazzer'
},
plugins: [
rollupNodeResolve(),
rollupCommonJs(),
rollupBabel(config.babel),
rollupUglify()
],
rollup: rollup
})
.pipe(source('jazzer.min.js'))
.pipe(gulp.dest(config.paths.dist));
});
My Babel config is as follows:
{
presets: [
['@babel/preset-env', {
targets: {
ie: 11,
browsers: 'last 2 versions'
},
useBuiltIns: 'usage',
modules: false,
debug: true
}]
],
ignore: ['node_modules']
}
When I comment out the line with rollupNodeResolve
, disabling the plugin, it compiles, but gives me a warning that 'regenerator-runtime/runtime' is imported by src/jazzer.js, but could not be resolved – treating it as an external dependency
, for example. Commenting out ignore: ['node_modules']
results in Babel importing it way too much stuff and producing a bundle of 83 kb—so that's not the way, either.
Hope someone can help me out! And here's the whole repo, if you'd like to check it out and see for yourself.
This is a bug in rollup-plugin-babel. I've filed it for you: https://github.com/rollup/rollup-plugin-babel/issues/192