optimize-plugin icon indicating copy to clipboard operation
optimize-plugin copied to clipboard

Not a webpack bundle unhandled rejection on every chunk

Open keepitterron opened this issue 4 years ago • 7 comments

Multi entry webpack 4 (latest) configuration on Node 14. It does this for every chunk

errored out during transformation  Error: /Users/claudio/Projects/loom/js/404-3594367e1117c0d15bb5.js: Not a webpack bundle
    at mod (/Users/claudio/Projects/loom/node_modules/optimize-plugin/dist/worker.js:203:15)
    at /Users/claudio/Projects/loom/node_modules/optimize-plugin/dist/worker.js:211:9
    at Array.forEach (<anonymous>)
    at getWebpackModules (/Users/claudio/Projects/loom/node_modules/optimize-plugin/dist/worker.js:207:10)
    at getWebpackBootstrap (/Users/claudio/Projects/loom/node_modules/optimize-plugin/dist/worker.js:85:25)
    at /Users/claudio/Projects/loom/node_modules/optimize-plugin/dist/worker.js:256:29
    at Array.forEach (<anonymous>)
    at PluginPass.Program (/Users/claudio/Projects/loom/node_modules/optimize-plugin/dist/worker.js:255:26)
    at newFn (/Users/claudio/Projects/loom/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/visitors.js:175:21)
    at NodePath._call (/Users/claudio/Projects/loom/node_modules/optimize-plugin/node_modules/@babel/traverse/lib/path/context.js:55:20) {
  type: 'Error',
  code: 'BABEL_TRANSFORM_ERROR'
}

Any pointers? 🙏

keepitterron avatar Dec 12 '20 21:12 keepitterron

Hiya - this seems the same as the second issue mentioned in #7. Are you able to share your Webpack configuration - in particular the mode, target and output options?

developit avatar Dec 14 '20 02:12 developit

Absolutely!

{
  "entry":{
    ...multiple entries
  },
  "output":{
     "path":"/Users/claudio/Projects/loom/dist/webpack",
     "publicPath":"https://cdn.loom.com/assets/",
     "filename":"js/[name]-[contenthash].js"
  },
  "devtool":false,
  "module":{
     "rules":[...rules]
  },
  "optimization":{
     "moduleIds":"hashed",
     "splitChunks":{
        "cacheGroups":{
           "default":false,
           "commons":{
              "name":"commons",
              "test":{
                 
              },
              "chunks":"all",
              "minChunks":3
           }
        }
     },
  },
  "plugins":[...plugins],
  "resolve":{...aliases only},
  "mode":"production"
}

babel.config contains preset/react and preset/env with no modules nor target options set.

keepitterron avatar Dec 14 '20 11:12 keepitterron

Awesome, thanks for this. I will try to set up a test case. I likely missed some bundle parsing cases for multi-entry since I avoid using multi-entry whenever possible for performance reasons.

developit avatar Dec 18 '20 16:12 developit

Oh that's very interesting. I can intuitively understand why would it be a performance drain, do you have any links where I can learn more (multi entry webpack)? 🙏 I'll do some digging of my own in the meanwhile :)

keepitterron avatar Dec 20 '20 09:12 keepitterron

@keepitterron it's a little buried in the docs, but there now: https://webpack.js.org/plugins/module-concatenation-plugin/#optimization-bailouts

developit avatar Dec 21 '20 16:12 developit

We bundle multiple separate 'apps' so we definitely need multiple entries, not something we can avoid unfortunately.

3zzy avatar Dec 28 '20 00:12 3zzy

For those hitting this issue, you can disable automatic modernization via new OptimizePlugin({ modernize: false }). This improves performance, but will use the unmodified ES5 source of most npm modules since they do not publish modern code.

developit avatar Feb 24 '21 22:02 developit