Vue打包出錯處理
阿新 • • 發佈:2020-07-13
背景
開發反饋一個Vue專案打包失敗,讓我處理下。
基於以下環境:
[root@iZ88636htauZ bin]# ./node -v
v10.20.1
[root@iZ88636htauZ bin]# ./npm -v
6.14.4
[root@iZ88636htauZ bin]# ./vue -V
@vue/cli 4.4.6
報錯如下:
11:36:19 npm ERR! code ETARGET 11:36:19 npm ERR! notarget No matching version found for [email protected]. 11:36:19 npm ERR! notarget In most cases you or one of your dependencies are requesting 11:36:19 npm ERR! notarget a package version that doesn't exist. 11:36:19 npm ERR! notarget 11:36:19 npm ERR! notarget It was specified as a dependency of 'social-security' 11:36:19 npm ERR! notarget 11:36:33 11:36:33 npm ERR! A complete log of this run can be found in: 11:36:33 npm ERR! /root/.npm/_logs/2020-07-13T03_36_19_295Z-debug.log 11:36:33 Build step 'Execute shell' marked build as failure 11:36:33 Finished: FAILURE
查了一下報錯,網上都是說要強制清快取:
刪除 node_modules、package-lock.json,執行 npm cache clean --force
,重新安裝依賴,還是一樣的報錯。
rm -rf node_modules
rm -f package-lock.json
npm cache clean --force
npm install
重新去看報錯第二句 npm ERR! notarget No matching version found for [email protected].
,去檢視 package.json ,發現裡面寫的是 [email protected],手動安裝 2.8.7版本後再次安裝依賴,打包成功了。
npm install [email protected]
npm install
總不能每次都手動安裝吧,再次檢視 package.json,發現有的寫 ^,有的寫 ~ 符號,這倆有啥區別?
"vant": "^2.8.7",
"vue": "~2.6.11",
網上查了一下,
- ^ 是最近的一個大版本,"vant": "^2.8.7",會自動匹配 2.x.x,但不包括3.x.x
- ~ 是最近的小版本, "vue": "~2.6.11",會匹配2.6.x,不匹配2.7.11
於是把 vant": "^2.8.7" 改為 vant": "~2.8.7" ,測試打包成功。