背景
開發反饋一個Vue項目打包失敗,讓我處理下。
Vue項目的打包項目是這樣,從gitlab拉代碼,然后npm install安裝依賴,npm run build-pro打包,通過rsync將打包出來的html文件同步到Nginx的html目錄下,並自動在Nginx下增加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 vant@2.9.1.
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 vant@2.9.1.
,去查看 package.json ,發現里面寫的是 vant@2.8.7,手動安裝 2.8.7版本后再次安裝依賴,打包成功了。
npm install vant@2.8.7
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" ,測試打包成功。