How to fix 'TypeError: Cannot read property 'minify' of undefined' in terser-webpack-plugin when building a new Vue CLI 3 project?

How to fix 'TypeError: Cannot read property 'minify' of undefined' in terser-webpack-plugin when building a new Vue CLI 3 project?

我使用 Vue CLI 3 创建了一个新项目(配置:babel、pwa、eslint、mocha)。 运行 使用 npm run serve 的测试环境运行良好,但我无法构建用于生产的项目。

我安装了当前版本的 Vue CLI 3 并尝试创建具有不同配置的项目。我在构建项目时收到以下错误消息。

js/app.bb3f3c6e.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at minify (/Users/.../untitled/node_modules/terser-webpack-plugin/dist/minify.js:176:23)
    at module.exports (/Users/.../untitled/node_modules/terser-webpack-plugin/dist/worker.js:13:40)
    at handle (/Users/.../untitled/node_modules/worker-farm/lib/child/index.js:44:8)
    at process.<anonymous> (/Users/.../untitled-adventure/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 processTicksAndRejections (internal/process/next_tick.js:76:17)

这是 (vuejs/vue-cli#3407)terser 3.16 依赖关系的已知问题。

解决方法是暂时安装 3.14:

npm i terser@3.14