我正在关注的WebPack的基础教程从这个链接:https://webpack.js.org/guides/getting-started/
我运行npx webpack
时失败,并显示以下错误:
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)
/dist
index.html
/node_modules
/src
index.js
package-lock.json
package.json
<!doctype html>
<html>
<head>
<title>Getting Started</title>
</head>
<body>
<script src="main.js"></script>
</body>
</html>
import _ from 'lodash';
function component() {
let element = document.createElement('div');
element.innerHTML = _.join(['hello', 'webpack'], ' ');
return element;
}
document.body.appendChild(component());
{
"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"
}
}
答案 0 :(得分:14)
这是一个错误,您可以通过安装terser v3.14来解决它
只需运行:
npm i -D terser@3.14
来源:https://github.com/vuejs/vue-cli/issues/3407#issuecomment-459985313
答案 1 :(得分:0)
解决方案:
npm install terser@3.14.1 --save-dev