大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
ERROR in xxx.js from UglifyJs
问题
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
按照以上方法对环境进行重新配置,依然报错!
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配置文件,亲测可以正确打包,无报错现象.
{
"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
明天的你一定会感谢现在拼命的自己!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/193342.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...