Vue 包版本不匹配

Gaa*_*aax 1 vue.js jestjs

我正在尝试通过 jest 向现有的 vue 项目添加单元测试,但是当我尝试运行我的第一个测试时,我收到一个错误消息

Vue 包版本不匹配:

- vue@2.5.16
- vue-template-compiler@2.6.6

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.
Run Code Online (Sandbox Code Playgroud)

但是看看我的包,我当前的 vue 版本2.6.6 而不是 2.5.16。我不知道它在哪里看到这个 2.5.16 版本。我没有全局安装 vue,只有@vue/cli@3.4.0。任何帮助,将不胜感激。您可以在下面找到包含我的 jest 配置的 package.json。

- vue@2.5.16
- vue-template-compiler@2.6.6

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.
Run Code Online (Sandbox Code Playgroud)

All*_*rku 7

您已经 "vue": "^2.6.6",并且"vue-template-compiler": "^2.6.6",按照您的package.json意思,将安装任何与2.6.6或更高版本匹配的版本,以解释vue@2.5.16. 你的 package-lock.json 文件设置了包更新到的当前版本,你可以从那里验证 vue 和 vue-template-compiler 的版本

您可以在同一版本上运行npm updatenpm install vue-template-compiler@2.5.16 --save-dev获取两者

运行以下命令对我有帮助

npm install vue-template-compiler@2.5.16 --save-dev

注意。用您需要的正确版本替换版本号。就我而言,vue 的版本是2.5.16,vue-template-compiler 是 2.5.13,因此我将 vue-template-compiler 更新为 vue 的版本。

希望这有助于某人

Vue 包版本不匹配错误修复