terser-webpack-plugin: TypeError: Cannot read property 'javascript' of undefined

  • Operating System: OS X 10.15.7
  • Node Version: 12.16.0
  • NPM Version: 6.14.8
  • webpack Version: 5.1.2
  • terser-webpack-plugin Version: 5.0.0

Expected Behavior

Build doesn’t fail

Actual Behavior

Build fails with : TypeError: Cannot read property ‘javascript’ of undefined at /node_modules/terser-webpack-plugin/dist/index.js:366:38

Code

My config :

optimization: {
  minimize: true,
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          output: {
            comments: false
          },
       },
      extractComments: false
    }),
  ]
}

How Do We Reproduce?

Update version of webpack & terser to latest then make build of assets of project : https://github.com/oguilleux/webpack-gulp-wordpress-starter-theme

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 21
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Because terser-webpack-plugin@5 doesn’t have compatibility with webpack@4, please read readme, don’t understand why it is so hard

encountered the same problem, i am building my typescript babel react project.

i use v4.2.3 of terser-webpack-plugin, it builds successfully

@Tofandel seriously? Please read the CHANGELOG

@Jerry-zhk why need to spam?

This is by far one of the funniest GitHub issues i’ve seen.

webpack-stream uses webpack@4, so you got this problem https://github.com/shama/webpack-stream/blob/master/package.json#L37, sorry nothing to fix here, webpack should be in peer deps inside webpack-stream, not in dependencies

@alexander-akait you are getting a lot of thumbs down because you are not being pleasant in your responses. Instead of getting exasperated the first time someone asks a question and saying, “Seriously?! RTFM!!!” try exercising a little more patience and empathy. I understand you are dealing with a lot more than just this one GitHub issue, but one comment here isn’t spam. I’m trying to be nothing but honest and helpful here as I’ve sent my fair share of online messages that I regret. ✌

If you are using webpack v5 or above you do not need to install this plugin. Webpack v5 comes with the latest terser-webpack-plugin out of the box. Using Webpack v4, you have to install terser-webpack-plugin v4.

@oguilleux yep, we are working on it, release with fix will be today/tomorrow

This happenend to me with Webpack5.15.0 and Terser5.5.1 Problem was that I only did yarn add -D wepack and forgot to do yarn add -D webpack-cli not necessarily related to webpack4.