文章大纲

Vue打包报Vue packages version mismatch错误

2019-10-29 22:23:08

最近合并Vue代码,打包时报如下错误:

ERROR in static/js/vendor.8ab50ed6b74efd5287b2.js from UglifyJs

真是不知道怎么招她惹她了,她就自己使小性子。


查百度,如此说:由于 UglifyJs 只支持 ES5 而 element-ui 可能引入了一部分 ES6 的写法,从而导致 webpack 打包失败。

解决方法就是使用UglifyJs的其它支持ES6的版本,执行命令如下:

npm i -D uglifyjs-webpack-plugin@beta

结果没成功。

核实了相关代码(在build/webpack.base.js文件内),也是无误。

{
{
test: /\.js$/,
loader: 'babel-loader',
include: [
resolve('src'),
resolve('test'),
resolve('/node_modules/element-ui/src'),
resolve('/node_modules/element-ui/packages')
]
}
}

检查git log记录,也并没有误传代码。


然后分支切换尝试了一通,打包仍是报同样错误,无奈就重装了npm,再次打包,结果就是层林尽染:错误提示红遍了Vim会话框。


继续填坑,不过现在开始填旧坑带来的新坑。

一开始没怎么看提示,继续百度。有人说vue已经被弄脏了,用下面命令净化下:

npm install weex-toolkit -g
npm cache clean --force

重新打包,仍是鸟样。


本文是翟码农个人博客蓝翟红尘里的PHP专题下的的文章,转载请注明出处:http://www.zhai14.com/blog/7e1ca319336e8bb3f822be6d172ffd65.html


百度来的都没试成功,没办法,只好静下心来看错误提示了。整个儿太大块了,就只展示冰山一角了:

 Vue packages version mismatch:
- vue@2.2.10
- vue-template-compiler@2.5.2
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

检查根目录下package.json文件,vue版本如下:

"dependencies": {
"vue": "^2.6.10",
},

所以我就想着去提高vue的版本,使其与配置文件一致:

npm install vue@2.6.10 --save

重新打包后仍然报错,但是vue版本有变化了。

 Vue packages version mismatch:
- vue@2.6.10
- vue-template-compiler@2.5.2
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.


错误提示要求vue和vue-template-compiler必须版本一致,所以现在还需要提高vue-template-compiler的版本:

npm update vue-template-compiler

重新打包,ok,新坑埋好了,旧坑又出来了:

ERROR in static/js/vendor.8ab50ed6b74efd5287b2.js from UglifyJs

怀疑自己切换分支,做了一些操作,影响到了啥吧。继续核实build/webpack.base.js文件,发现element-ui部分没有了,就加上去了。重新打包,额,结果没报错,而是直接来了个单词Killed(被杀死)。

好吧,实在被玩弄够了,我要放手了。


隔天早上我重新来尝试打包,居然ok了。



我要评论
评论列表