问题描述
这是我第一次使用react构建一个框架应用,并且在cmd提示符下运行npm run-script build
时遇到此错误。
Failed to compile.
static/js/main.9516bce8.js from UglifyJs
Unexpected token: operator (>) [./~/aframe/dist/aframe-master.js:57303,0][static/js/main.9516bce8.js:80512,32]
"aframe": "^1.0.4"
"webpack": {
"version": "2.6.1","resolved": "https://registry.npmjs.org/webpack/-/webpack-2.6.1.tgz","integrity": "sha1-LgRX8KuxrF3zqxBsacZy8jZ4Xwc=","requires": {
"acorn": "^5.0.0","acorn-dynamic-import": "^2.0.0","ajv": "^4.7.0","ajv-keywords": "^1.1.1","async": "^2.1.2","enhanced-resolve": "^3.0.0","interpret": "^1.0.0","json-loader": "^0.5.4","json5": "^0.5.1","loader-runner": "^2.3.0","loader-utils": "^0.2.16","memory-fs": "~0.4.1","mkdirp": "~0.5.0","node-libs-browser": "^2.0.0","source-map": "^0.5.3","supports-color": "^3.1.0","tapable": "~0.2.5","uglify-js": "^2.8.27","watchpack": "^1.3.1","webpack-sources": "^0.2.3","yargs": "^6.0.0"
},
根据我的研究,我猜测我使用的uglify版本不支持ES6 但是我在网上找不到任何可以帮助我更新或替换uglify-js来处理ES6的东西
解决方法
您可以使用
进行更新 npm update uglify-js
将软件包更新为满足版本标记的最新版本。
如果此新版本不起作用,则可以将其更新为特定版本
npm update uglify-js@3.0.5
或仅将其更新为最新版本
npm update uglify-js@latest
要小心,因为更新可能会破坏一些现有代码
,terser-webpack-plugin使用webpack v4为我工作。它确实支持ES6 +