Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
oguilleux opened this issue Oct 15, 2020 · 19 comments
Closed

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

oguilleux opened this issue Oct 15, 2020 · 19 comments

Comments

@oguilleux
Copy link

  • 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

@oguilleux oguilleux changed the title TypeError: Cannot read property 'javascript' of undefined at /Users/olivier/wwwlocal/corsairesv2/wp-content/themes/corsaires-theme/node_modules/terser-webpack-plugin/dist/index.js:366:38 TypeError: Cannot read property 'javascript' of undefined Oct 15, 2020
Planeshifter added a commit to isle-project/isle-editor that referenced this issue Oct 16, 2020
@Jerry-zhk
Copy link

Jerry-zhk commented Oct 16, 2020

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
Copy link
Member

@Jerry-zhk why need to spam?

@alexander-akait
Copy link
Member

alexander-akait commented Oct 16, 2020

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

@oguilleux
Copy link
Author

I'm not using webpack 4 but webpack 5.

@alexander-akait
Copy link
Member

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

@oguilleux
Copy link
Author

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
Copy link
Member

alexander-akait commented Oct 16, 2020

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
Copy link
Author

Okay thanks for highlighting this !

@oguilleux
Copy link
Author

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
Copy link
Member

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

@Tofandel
Copy link

Tofandel commented Nov 9, 2020

Any news? Still having this issue with 5.0.3

@alexander-akait
Copy link
Member

@Tofandel seriously? Please read the CHANGELOG

@woldtwerk
Copy link

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
Copy link

james0r commented Apr 29, 2021

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

@alexander-akait
Copy link
Member

alexander-akait commented Apr 30, 2021

Don't know why a lot of 👎 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
Copy link

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
Copy link
Author

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

@as-zlynn-philipps
Copy link

@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
Copy link
Member

@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 #335 (comment), that problem #335 (comment) 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants