shellscape / webpack-manifest-plugin

webpack plugin for generating asset manifests
MIT License
1.44k stars 184 forks source link

Nameless chunks result in an exception #16

Closed rgrove closed 8 years ago

rgrove commented 8 years ago

As of commit 2ff2950f (which landed in version 1.0.0), webpack-manifest-plugin throws the following exception when it encounters a nameless chunk:

/path/redacted/node_modules/webpack-manifest-plugin/lib/plugin.js:43
      var chunkName = chunk.name.replace(this.opts.stripSrc, '');
                                ^

TypeError: Cannot read property 'replace' of null
    at ManifestPlugin.<anonymous> (/path/redacted/node_modules/webpack-manifest-plugin/lib/plugin.js:43:33)
    at Array.reduce (native)
    at ManifestPlugin.<anonymous> (/path/redacted/node_modules/webpack-manifest-plugin/lib/plugin.js:42:39)
    at Compiler.applyPluginsAsync (/path/redacted/node_modules/tapable/lib/Tapable.js:71:13)
    at Compiler.emitAssets (/path/redacted/node_modules/webpack/lib/Compiler.js:226:7)
    at Compiler.<anonymous> (/path/redacted/node_modules/webpack/lib/Compiler.js:184:10)
    at /path/redacted/node_modules/webpack/lib/Compiler.js:403:12
    at Compiler.next (/path/redacted/node_modules/tapable/lib/Tapable.js:67:11)
    at Compiler.<anonymous> (/path/redacted/node_modules/webpack/lib/CachePlugin.js:40:4)
    at Compiler.applyPluginsAsync (/path/redacted/node_modules/tapable/lib/Tapable.js:71:13)

It looks like @shamrin called this out as a bug in PR #14, but for some reason it was never fixed and the PR was merged anyway.

stevenp commented 8 years ago

+1 on this. To avoid this error I had to change:

require.ensure([], (require) => {
  cb(null, require('../containers/FormContainer/FormContainer.js'));
});

to:

require.ensure([], (require) => {
  cb(null, require('../FormContainer/FormContainer.js'));
}, 'Form');

@rgrove: On a side note, I had a heck of a time figuring out that this plugin was the source of my error. How did you get that stack trace? I was running webpack through Grunt, and only got the TypeError with no additional detail.

rgrove commented 8 years ago

@stevenp I'm running the webpack CLI directly here. It's been a while since I last used Grunt, but I seem to recall it hides stack traces unless you pass --stack on the command line. Maybe that's why you didn't see a stack trace?

jordaaash commented 8 years ago

Yeah, #14 was merged before I had a chance to revisit it. I never ran into this issue when I was working on it, probably because I'm not doing code splitting. If anyone could share a failing test or example project to replicate this so I can see how it's being used, I'm happy to work on fixing it.

npbee commented 8 years ago

I started a forked branch with a failing test here:

https://github.com/npbee/webpack-manifest-plugin/blob/unamed-chunks/spec/plugin.spec.js#L181

Happy to send it as a PR if you'd like to work off of it. My use case here (and I suspect for @stevenp based on the example) is for dynamically loading routes via React Router, so a good example app if you need it could be this one from their docs: https://github.com/reactjs/react-router/tree/master/examples/huge-apps.

tendant commented 8 years ago

I am seeing this issue as well. The problem is "chunk.name" is null in some cases.

We can look into upstream see how to make sure "chunk.name" always exist. Or in the plugin, we can use some other alternatives as name like: chunk.modules[0].userRequest

I don't know which way might give us reliable name.

Any comments?

rupesh1 commented 8 years ago

With Webpack 2 we can use System.import (instead of require.ensure) which doesn't allow the naming of chunks (as per the loader spec).

The Webpack team have indicated they won't deviate from the loader spec i.e. they will not support naming System.import chunks https://github.com/webpack/webpack/issues/1949

alexgorbatchev commented 8 years ago

Also seeing this issue.

gmac commented 8 years ago

Addressed in https://github.com/danethurber/webpack-manifest-plugin/pull/17.

gmac commented 8 years ago

Updates to PR: https://github.com/danethurber/webpack-manifest-plugin/pull/17. Exceptions are fixed, and nameless chunks report their generated files into the manifest.