23

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
> a@1.0.0 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"
Quill
  • 2,729
  • 1
  • 33
  • 44
SakthiSureshAnand
  • 1,324
  • 16
  • 32

1 Answers1

74

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

Sated
  • 741
  • 3
  • 2