Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'javascript' of undefined + terser webpack plugin + react js

I recently added terser-webpack-plugin to minify my create react app code. But while build the project I got an error like TypeError: Cannot read property 'javascript' of undefined. Below are some logs from my console. Please let me know of any workarounds or changes to fix it.

Console logs:

D:\a>npm run build:qa
> [email protected] build:qa D:\a
> cross-env webpack --env.ENVIRONMENT=qa --config ./webpack.config.js --mode production --progress --colors
D:\a\node_modules\terser-webpack-plugin\dist\index.js:400
      const hooks = compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);
                                     ^
TypeError: Cannot read property 'javascript' of undefined
    at D:\a\node_modules\terser-webpack-plugin\dist\index.js:400:38

webpack version im using:

"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
like image 959
SakthiSureshAnand Avatar asked Oct 25 '20 07:10

SakthiSureshAnand


1 Answers

Hi you are using Webpack 4 and Terser ^5.0.0. This version of Terser is for Webpack 5, you need to set version "terser-webpack-plugin": "^4.2.3", in package.json file

like image 164
Sated Avatar answered Nov 19 '22 14:11

Sated