報錯信息如下:
1m[31mERROR in /var/lib/jenkins/workspace/CICD-libya-admin/src/main.ts[39m[22m [2m59:9[22m No overload matches this call. Overload 1 of 2, '(plugin: PluginObject<unknown> | PluginFunction<unknown>, options?: unknown): VueConstructor<Vue>', gave the following error. Argument of type '{ new (): Plugin; prototype: Plugin; }' is not assignable to parameter of type 'PluginObject<unknown> | PluginFunction<unknown>'. Property 'install' is missing in type '{ new (): Plugin; prototype: Plugin; }' but required in type 'PluginObject<unknown>'. Overload 2 of 2, '(plugin: PluginObject<any> | PluginFunction<any>, ...options: any[]): VueConstructor<Vue>', gave the following error. Argument of type '{ new (): Plugin; prototype: Plugin; }' is not assignable to parameter of type 'PluginObject<any> | PluginFunction<any>'. Property 'install' is missing in type '{ new (): Plugin; prototype: Plugin; }' but required in type 'PluginObject<any>'.
經過對報錯信息的分析,應該是ts類型不一致導致的。但是本地卻是正常的,后來刪除node_modules后重新運行,本地出現和測試環境一模一樣的報錯。於是,打開VS Code,找到src/main.ts文件進行查看。發現是以下代碼出錯。

vue.use方法的類型為:

VueCompositionApi的類型為:

初步推斷:兩個.ts文件都是node_modules中自帶的,那問題應該出在版本上吧。於是上https://www.npmjs.com/ 搜索@vue/composition-api。

發現上次發布是一天前,而我們Jenkins上上一次成功構建是11月12日。難道是因為我們下載到了最新版本導致不兼容嗎?
帶着疑問,我打開node_modules中的@vue/composition-api/package.json文件查看,果然,下載到了最新版本。

新的疑問:package.json中不是定義了老的版本號嗎?為什么會下載到最新版本?

帶着疑問我在網上搜索“如何鎖定package.json中定義的依賴版本”,找到了解決方案。npm shrinkwrap能夠鎖定package.json中定義的依賴版本。
執行后能夠生成 npm-shrinkwrap.json文件,有了該文件,就不怕npm和cnpm給我們下載最新版本的依賴啦。
