ERROR in app.bundle.js from UglifyJs
Unexpected token: name «element», expected: punc «;» [app.bundle.js:106,8]
在用webpack对代码打包的时候报错,在网上找到了类似的答案,还是没有解决我的问题.
https://stackoverflow.com/questions/41254538/error-in-bundle-js-from-uglifyjs
http://www.cnblogs.com/aredleave/p/7586911.html
https://segmentfault.com/a/1190000011212544
按照以上方法对环境进行重新配置,依然报错!
1 2 3 4 |
ERROR in ./src/index.js Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module '@babel/core' babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'. |
通过代码报错原因是 babel-loader 版本问题,因为 babel-loader 用的最新的版本,和 UglifyJs 不兼容.
通过运行下面代码对babel-loader进行重新安装(低版本).
npm install --save-dev babel-loader@7
通过修改后的package.json配置文件,亲测可以正确打包,无报错现象.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
{ "name": "kankan", "version": "1.0.0", "description": "kankan", "main": "webpack.config.js", "scripts": { "start": "webpack-dev-server --open --config webpack.dev.js", "build": "webpack --config webpack.prod.js" }, "author": "kankan", "license": "ISC", "devDependencies": { "babel": "^6.23.0", "babel-core": "^6.26.3", "babel-loader": "^7.1.5", "babel-preset-es2015": "^6.24.1", "clean-webpack-plugin": "^2.0.1", "css-loader": "^2.1.1", "express": "^4.16.4", "html-webpack-plugin": "^3.2.0", "style-loader": "^0.23.1", "uglifyjs-webpack-plugin": "^2.1.2", "webpack": "^4.30.0", "webpack-cli": "^3.3.1", "webpack-dev-middleware": "^3.6.2", "webpack-dev-server": "^3.3.1", "webpack-manifest-plugin": "^2.0.4", "webpack-merge": "^4.2.1" } } |
奇卡奇卡 哈哈哈
个人主页:https://kankan.fun
from:https://blog.csdn.net/qq_38025939/article/details/89576282