Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npx webpack - Cannot read property 'minify' of undefined

I'm following the basic tutorial of webpack from this link : https://webpack.js.org/guides/getting-started/

when I run npx webpack it fails with the following error:

ERROR in main.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at minify (/Users/name/Documents/practice/webpack/webpack-demo/node_modules/terser-webpack-plugin/dist/minify.js:175:23)
    at module.exports (/Users/name/Documents/practice/webpack/webpack-demo/node_modules/terser-webpack-plugin/dist/worker.js:13:40)
    at handle (/Users/name/Documents/practice/webpack/webpack-demo/node_modules/worker-farm/lib/child/index.js:44:8)
    at process.<anonymous> (/Users/name/Documents/practice/webpack/webpack-demo/node_modules/worker-farm/lib/child/index.js:51:3)
    at process.emit (events.js:188:13)
    at emit (internal/child_process.js:828:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19)
  • node version: v11.6.0
  • npm version: 6.5.0-next.0
  • webpack version: 4.29.0
  • webpack-cli version: 3.2.1

folder structure

/dist
  index.html
/node_modules
/src
  index.js
package-lock.json
package.json

index.html

<!doctype html>
<html>
  <head>
    <title>Getting Started</title>
  </head>
  <body>
    <script src="main.js"></script>
  </body>
</html>

index.js

import _ from 'lodash';

function component() {
  let element = document.createElement('div');
  element.innerHTML = _.join(['hello', 'webpack'], ' ');
  return element;
}

document.body.appendChild(component());

package.json

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.29.0",
    "webpack-cli": "^3.2.1"
  },
  "dependencies": {
    "lodash": "^4.17.11"
  }
}

like image 811
user8659363 Avatar asked Feb 03 '19 03:02

user8659363


1 Answers

It's a bug and you can fix it by installing terser v3.14

Simply run:

npm i -D [email protected]

Source: https://github.com/vuejs/vue-cli/issues/3407#issuecomment-459985313

like image 64
user8659363 Avatar answered Nov 11 '22 11:11

user8659363