webpack-contrib / terser-webpack-plugin

Terser Plugin
MIT License
1.95k stars 157 forks source link

TypeError: Cannot read property 'javascript' of undefined #335

Closed oguilleux closed 3 years ago

oguilleux commented 4 years ago

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

Jerry-zhk commented 4 years ago

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

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

alexander-akait commented 4 years ago

@Jerry-zhk why need to spam?

alexander-akait commented 4 years ago

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

oguilleux commented 4 years ago

I'm not using webpack 4 but webpack 5.

alexander-akait commented 4 years ago

@oguilleux https://github.com/oguilleux/webpack-gulp-wordpress-starter-theme/blob/master/package.json#L66 really?

oguilleux commented 4 years ago

Please take a look at my initial post.

You asked how do we reproduce?

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

So if you update package.json to webpack 5.1.2 and terser-webpack-plugin to 5.0.0 and make the build you will reproduce the bug.

alexander-akait commented 4 years ago

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

oguilleux commented 4 years ago

Okay thanks for highlighting this !

oguilleux commented 4 years ago

Solved by updating my gulp pipe and passing webpack in webpack-steam as you can see here.

Now I have this showing up :

[DEP_WEBPACK_WATCH_WITHOUT_CALLBACK] DeprecationWarning: A 'callback' argument need to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.

It seems similar to this issue though my build doesn't fail. I'll wait for your PR.

alexander-akait commented 4 years ago

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

Tofandel commented 3 years ago

Any news? Still having this issue with 5.0.3

alexander-akait commented 3 years ago

@Tofandel seriously? Please read the CHANGELOG

woldtwerk commented 3 years ago

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.

james0r commented 3 years ago

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

alexander-akait commented 3 years ago

Don't know why a lot of :-1: webpack-stream had webpack v4 in dependencies, so when you run npm i you will have webpack v4 and v5 in node_modules, because we previously used import webpack from 'webpack'; and you can have webpack v4 in node_modules/webpack due npm logic, we got webpack v4 but API was written for webpack v5. We rewritten our code do not use import webpack from 'webpack'; in favor compiler.webpack, so nobody faced with these problems in future.

I don’t know where it’s so much negative in people, even more using emoji in these case is not help somebody, if you faced with a problem please provide information, so I can help you, thanks

tomatobybike commented 3 years ago

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 commented 3 years ago

@tomatobybike You do if you want to override its settings.

as-zlynn-philipps commented 3 years ago

@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. ✌

alexander-akait commented 3 years ago

@as-zlynn-philipps I don't say any angry word, just ask a question and answer there was problem, even more I describe the problem and there it should be fixed https://github.com/webpack-contrib/terser-webpack-plugin/issues/335#issuecomment-710004332, that problem https://github.com/webpack-contrib/terser-webpack-plugin/issues/335#issuecomment-709716106 is not helpful, it was clear from the first message, sometimes I can't just take and immediately answer what the problem is, but I did it the next day