webpack-contrib / bundle-loader

Bundle Loader
MIT License
658 stars 59 forks source link

Breaks in Webpack 4 with `name` option #69

Closed statianzo closed 6 years ago

statianzo commented 6 years ago

Using bundle-loader and specifying a name throws an error in Webpack 4.

import other from 'bundle-loader?lazy&name=myChunk!./other';

fails compilation with the error

ERROR in ./node_modules/bundle-loader?lazy&name=myChunk!./src/other.js

Module build failed: TypeError: Cannot read property 'context' of undefined

    at Object.module.exports.pitch (/app/node_modules/bundle-loader/index.js:13:43)

@ ./src/index.js 1:0-60 3:0-5

It appears that Webpack 4 is not setting this.options when invoking loader functions. From bundle-loader source:

var options = {
  context: query.context || this.options.context, // <-- Cannot read property 'context' of undefined
  regExp: query.regExp
};

I'd be glad to make a PR to fix this, but I'm not sure if the problem is a Webpack 4 issue or bundle-loader. If it's bundle-loader's issue, what's the desired behavior?

Versions

Webpack: 4.0.0-beta.0 bundle-loader: 0.5.5

Example

Glitch.me project that reproduces the error

statianzo commented 6 years ago

According to the Webpack Medium that this.options was deprecated in Webpack 3 and removed in 4.

https://medium.com/webpack/webpack-4-migration-guide-for-plugins-loaders-20a79b927202

Its replacement should be this.rootContext. I'll put together a PR for that.