若是你使用了element-ui
的el-tabs
組件,而且想要單獨升級element-ui
至2.10.0
,你會發現,使用了el-tabs
組件的頁面只要打開就卡死。緣由是element-ui~2.10.0
採用了不兼容vue~2.5.10
的寫法。因而我嘗試系統性升級vue
全家桶,這也是爲系統賦予更多能力作準備。結果遇到一些報錯,這裏記錄一下。javascript
vue: 2.5.10
css
vue-loader: 13.5.0
vue
vue-router: 3.0.1
java
vuex: 3.0.1
node
axios: 0.17.1
webpack
element-ui: 2.2.2
ios
vue: 2.6.10
git
vue-loader: 15.7.0
github
vue-router: 3.0.3
web
vuex: 3.1.1
axios: 0.18.1
element-ui: 2.10.0
修改package.json
中的依賴包版本號以後,npm install
一波後就報錯了。
Vue packages version mismatch: - vue@2.6.10 - vue-template-compiler@2.5.10 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. @ ./src/router/modules/test/index.js 22:23-67 @ ./src/router/common.js @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:9532 webpack/hot/dev-server babel-polyfill ./src/main.js
分析:vue
和vue-template-compiler
兩個包的版本不匹配,須要升級vue-template-compile
。github搜索這個包搜不到,最後在npm包官網找到了。
解決方案:升級vue-template-compile: 2.6.10
| | <section> | <el-form class="cl-add-form" :model="dataForm" :rules="rules" ref="dataForm" label-width="125px"> | <el-form-item label="法定節假日名稱" prop="name"> @ ./src/views/backend/enterprise/holiday/add-public-holiday.vue 1:0-97 30:4-35:6 30:81-35:5 @ ./src/views lazy ^\.\/.*$ @ ./src/authority/generate-routes.js @ ./src/store/modules/user.js @ ./src/store/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:9532 webpack/hot/dev-server babel-polyfill ./src/main.js error in ./src/views/backend/enterprise/holiday/add-special-holiday.vue?vue&type=template&id=09f84cb0& Module parse failed: Unexpected token (2:0) You may need an appropriate loader to handle this file type.
分析:經觀察,發現多是不識別vue
文件或其中某部分,因而從vue-loader
入手,也在網上查閱了一些資料,須要在webpack
的plugins
中加入vue-loader/lib/plugin
。
解決方案:
const VueLoaderPlugin = require('vue-loader/lib/plugin') plugins: [ new VueLoaderPlugin(), // 其餘插件 ... ]
(Emitted value instead of an instance of Error) ⚠️ PostCSS Loader Previous source map found, but options.sourceMap isn't set. In this case the loader will discard the source map entirely for performance reasons. See https://github.com/postcss/postcss-loader#sourcemap for more information. @ ./node_modules/vue-style-loader!./node_modules/css-loader?{"sourceMap":false}!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/lib?{"sourceMap":false}!./node_modules/vue-loader/lib?{"loaders":{"css":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}}],"postcss":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}}],"less":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}},{"loader":"less-loader","options":{"sourceMap":false}}],"sass":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}},{"loader":"sass-loader","options":{"indentedSyntax":true,"sourceMap":false}}],"scss":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}},{"loader":"sass-loader","options":{"sourceMap":false}}],"stylus":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}},{"loader":"stylus-loader","options":{"sourceMap":false}}],"styl":["vue-style-loader",{"loader":"css-loader","options":{"sourceMap":false}},{"loader":"stylus-loader","options":{"sourceMap":false}}]},"cssSourceMap":false,"cacheBusting":true,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"}}!./src/views/iot-supervise/truck/truck-carousel.vue?vue&type=style&index=0&lang=css& 4:14-1577 14:3-18:5 15:22-1585 @ ./src/views/iot-supervise/truck/truck-carousel.vue?vue&type=style&index=0&lang=css& @ ./src/views/iot-supervise/truck/truck-carousel.vue @ ./src/views lazy ^\.\/.*$ @ ./src/authority/generate-routes.js @ ./src/store/modules/user.js @ ./src/store/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:9532 webpack/hot/dev-server babel-polyfill ./src/main.js
分析:這裏面的錯誤是關於postcss-loader
的,只要將config/index.js
中dev.cssSourceMap
設置爲true
便可。
升級過程當中還遇到了一個警告,雖然不影響功能,可是看着仍是很難受的。
in ./src/icons/svg/workList.svg svg-sprite-loader exception. 28 rules applies to D:\coollu\projects\coollu-v3\source-code\v1.0.1\update-elementui-test\src\icons\svg\workList.svg @ ./src/icons/svg \.svg$ @ ./src/icons/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:9532 webpack/hot/dev-server babel-polyfill ./src/main.js
搜索關鍵詞後,發現網上並無此類答案。所以我考慮是版本問題,因而升級svg-sprite-loader
至最新版本4.1.6
,解決了這個警告問題。
至此升級過程就完成了!順便一提,系統性升級必需要通過全面測試,不然你難以保證徹底向下兼容哦!