throwing an error if I disable source map in uglifyjs plugin

I think this is a more appropriate location to file this issue:
webpack-contrib/extract-text-webpack-plugin#98

I disabled extract text plugin and it still gives an error. Its probably in webpack.

So just re posting this:

I get an error if I turn off source map in

new webpack.optimize.UglifyJsPlugin({
    compress: {
        warnings: false
    }
    , sourceMap: false
  })

I’m trying to disable source map since my build takes 5 minutes long. Removing it yields 1 minute 40 seconds.

Here’s part of my stack trace

ERROR in bundle.js from UglifyJs
TypeError: Cannot read property 'sections' of null
    at new SourceMapConsumer (/var/www/project/node_modules/webpack/node_modules/webpack-core/node_modules/source-map/lib/source-map/source-map-consumer.js:24:21)
    at /var/www/project/node_modules/webpack/lib/optimize/UglifyJsPlugin.js:62:23
    at Array.forEach (native)
    at Tapable.<anonymous> (/var/www/project/node_modules/webpack/lib/optimize/UglifyJsPlugin.js:44:10)
    at Tapable.next (/var/www/project/node_modules/webpack/node_modules/tapable/lib/Tapable.js:69:14)
    at Tapable.<anonymous> (/var/www/project/node_modules/webpack/lib/optimize/UglifyJsPlugin.js:136:4)
    at Tapable.applyPluginsAsync (/var/www/project/node_modules/webpack/node_modules/tapable/lib/Tapable.js:71:13)
    at Tapable.<anonymous> (/var/www/project/node_modules/webpack/lib/Compilation.js:564:9)
    at Tapable.next (/var/www/project/node_modules/webpack/node_modules/tapable/lib/Tapable.js:67:11)
    at ExtractTextPlugin.<anonymous> (/var/www/project/node_modules/extract-text-webpack-plugin/index.js:303:4)
    at Tapable.applyPluginsAsync (/var/www/project/node_modules/webpack/node_modules/tapable/lib/Tapable.js:71:13)
    at Tapable.<anonymous> (/var/www/project/node_modules/webpack/lib/Compilation.js:560:8)
    at Tapable.next (/var/www/project/node_modules/webpack/node_modules/tapable/lib/Tapable.js:67:11)
    at ExtractTextPlugin.<anonymous> (/var/www/project/node_modules/extract-text-webpack-plugin/index.js:279:5)
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:52:16
    at done (/var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:248:21)
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:44:16
    at /var/www/project/node_modules/extract-text-webpack-plugin/index.js:270:6
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:52:16
    at done (/var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:248:21)
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:44:16
    at /var/www/project/node_modules/extract-text-webpack-plugin/index.js:267:13
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:187:20
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:239:13
    at _arrayEach (/var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:91:13)
    at _each (/var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:82:13)
    at Object.async.forEachOf.async.eachOf (/var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:238:9)
    at Object.async.forEach.async.each (/var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:215:22)
    at /var/www/project/node_modules/extract-text-webpack-plugin/index.js:241:11
    at /var/www/project/node_modules/extract-text-webpack-plugin/node_modules/async/lib/async.js:187:20

Author: Fantashit

16 thoughts on “throwing an error if I disable source map in uglifyjs plugin

  1. @sokra just tried reinstalling dependencies. Still getting the same error on build:

    ERROR in bundle.js from UglifyJs
    TypeError: Cannot read property 'sections' of null
        at new SourceMapConsumer 
  2. I am getting the same error here when using sourcemap false and –optimize-minimize (if I leave the optimize out it works).

  3. when using new UglifyJsPlugin and --opimize-minimize (or -p) you are adding the UglifyJsPlugin twice. Omit the CLI option.

  4. Is there a fix coming for this? In my opinion Webpack should be smart enough to omit one or the other f both are present.

  5. With Webpack 4, mode: 'production' will automatically add optimizations plugins.

    If you get the following warning/error message when building with mode: 'production', try fixing by below instruction.

    TypeError: Cannot read property 'sections' of null 👉 Remove `new UglifyJsPlugin` from plugins part
    schema id ignored LoaderOptionsPlugin              👉 Remove `new LoaderOptionsPlugin` plugin from config
    schema id ignored SourceMapDevToolPlugin           👉 Remove `devtool` config
    
  6. @damianobarbati, you might pass it as minimizer option rather than push it as plugin part.

    const configs = {
      mode: "production",
      entry: "./index",
      output: {
        filename: "bundle.js"
      },
      optimization: {
        minimize: true,
        minimizer: [
          new UglifyJsPlugin({
            sourceMap: true,
            uglifyOptions: {
              // ...
            }
          })
        ]
      }
    };
  7. Another way I was able to get rid of this issue was by removing devtool: 'source-map' from webpack config.

Comments are closed.