webpack-emit-all-plugin icon indicating copy to clipboard operation
webpack-emit-all-plugin copied to clipboard

TypeError: Cannot read property '_value' of null

Open dzg opened this issue 6 years ago • 8 comments
trafficstars

[1]                     const source = mod._source._value;
[1]                                                ^
[1] 
[1] TypeError: Cannot read property '_value' of null
[1]     at modules.forEach.mod (/Users/.../node_modules/webpack-emit-all-plugin/index.js:28:48)
[1]     at Array.forEach (<anonymous>)
[1]     at compiler.hooks.afterCompile.tapAsync (/Users/.../node_modules/webpack-emit-all-plugin/index.js:19:25)
[1]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/.../node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:20:1)
[1]     at AsyncSeriesHook.lazyCompileHook (/Users/.../node_modules/tapable/lib/Hook.js:154:20)
[1]     at compilation.seal.err (/Users/.../node_modules/webpack/lib/Compiler.js:628:31)
[1]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/.../node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
[1]     at AsyncSeriesHook.lazyCompileHook (/Users/.../node_modules/tapable/lib/Hook.js:154:20)
[1]     at hooks.optimizeAssets.callAsync.err (/Users/.../node_modules/webpack/lib/Compilation.js:1329:35)
[1]     at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/.../node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! [email protected] client: `webpack-dev-server --mode development --devtool inline-source-map --hot`
[1] npm ERR! Exit status 1
[1] npm ERR! 
[1] npm ERR! Failed at the [email protected] client script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.```

dzg avatar Apr 30 '19 17:04 dzg

encountering this as well

maclockard avatar May 05 '19 20:05 maclockard

encountered using webpack v4.29.6

andykais avatar May 14 '19 16:05 andykais

Greetings. Excellent plugin. Any updates on this matter?

Thank you!

geekox86 avatar Jun 08 '19 23:06 geekox86

Encountered using webpack v4.39.1

I added some console logs, to see when _source is null or not. This is my output

mod NormalModule has Source? true
mod NormalModule has Source? true
mod NormalModule has Source? true
mod ConcatenatedModule has Source? false

Appears like if a ConcatenatedModule is received, mod._source is null.

breautek avatar Aug 06 '19 16:08 breautek

Encountered using webpack v4.39.1

I added some console logs, to see when _source is null or not. This is my output

mod NormalModule has Source? true
mod NormalModule has Source? true
mod NormalModule has Source? true
mod ConcatenatedModule has Source? false

Appears like if a ConcatenatedModule is received, mod._source is null.

I am also encountering this issue and can verify @breautek's discovery.

Adding a line similar to how MultiModule is being handled makes the error goes away. However, I'm not sure if this is the proper approach or if the two types can be handled the same.

if (mod.constructor.name === 'ConcatenatedModule') return; or if (['MultiModule', 'ConcatenatedModule'].includes( mod.constructor.name)) return;

In the meantime, configuring webpack to not concatenate modules by default will fix the issue. However, depending on how big your project is this might affect performance, I believe, as this method of concatenating modules is meant to rollup dependent modules into one closure function for faster execution in the browser.

Here's an example:

module.exports = {
  mode: 'production',
  entry: {
    main: './index.js'
  },
  plugins: [
    new EmitAllPlugin(),
  ],
  optimization: {
    concatenateModules: false // set this to false
  }
};

heyitsjhu avatar Sep 23 '19 17:09 heyitsjhu

The same error. Webpack 4.40.1, Node 10.16.3

PerminovEugene avatar Oct 07 '19 15:10 PerminovEugene

any fix? assuming new webpack version broke this, don't know much about wp plugins but i'll dig in if no one else answers

visgotti avatar Nov 11 '19 01:11 visgotti

I found a fork of webpack-emit-all-plugin that works with WebPack 4.41.6. https://github.com/bv-loveholidays/webpack-emit-all-plugin/blob/master/index.js However, this plugin looks like a hack, it doesn't generate correctly source maps and doesn't resolve all imports properly.

korniychuk avatar Feb 14 '20 01:02 korniychuk