如何在Laravel Spark v4.0.9上修复"Vue软件包版本不匹配"错误?

Nat*_*ter 23 vue.js laravel-spark vuejs2

当我npm run dev在Laravel Spark v4.0.9应用程序上运行时,出现以下错误:

Module build failed: Error:

Vue packages version mismatch:

- vue@2.0.8
- vue-template-compiler@2.2.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)

package.json看起来像这样:

{
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "dependencies": {
    "axios": "^0.15.2",
    "bootstrap": "^3.0.0",
    "cross-env": "^3.2.3",
    "jquery": "^2.1.4",
    "js-cookie": "^2.1.0",
    "laravel-mix": "0.*",
    "moment": "^2.10.6",
    "promise": "^7.1.1",
    "sweetalert": "^1.1.3",
    "underscore": "^1.8.3",
    "urijs": "^1.17.0",
    "vue": "~2.0.1",
    "vue-resource": "^1.2.0",
    "vue-router": "^2.2.1",
    "vue-truncate-filter": "^1.1.6",
    "vuejs-datepicker": "^0.6.2"
  },
  "devDependencies": {
    "browser-sync": "^2.18.8",
    "browser-sync-webpack-plugin": "^1.1.4"
  }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下(在不同时间,不按顺序):

  • 删除node_modulesnpm install
  • 试着跑步yarnyarn upgrade
  • 删除vue-loader并重新安装
  • 指定vue和vue-template-compiler的确切版本,而不是将其保留到npm以安装或者纱线来确定依赖关系
  • 删除其他非必要的包(vue-router,vue-truncate-filter,vuejs-datepicker)并再次尝试以上所有方法
  • 把头撞在墙上

Jos*_*eie 19

对于vue ^2.5.17.

在你的 package.json

只需添加此内容devDependencies或更新以下版本vue-template-compiler:

  • "vue-template-compiler": "^2.5.17"

你会得到这个输出:

"devDependencies": {
  ...
  "lodash": "^4.17.4",
  "popper.js": "^1.14.4",
  "vue": "^2.5.17", // <= note the version
  "vue-template-compiler": "^2.5.17" // <= note the version
},
Run Code Online (Sandbox Code Playgroud)

之后,运行:

  • npm安装

Npm将仅更新更新的包.

  • 你知道为什么突然断掉吗?我从来没有更新过我的 npm,但它突然停止工作了。谢谢 (3认同)

小智 18

这对我有用:

  1. 修改package.json:

    “vue”: “^2.0.8",
    “vue-template-compiler”: “^2.1.8"
    
    Run Code Online (Sandbox Code Playgroud)
  2. 删除 node_modules

  3. npm install

  • 我认为不需要删除 node_modules,我面对它,只需安装模板,npm install 就可以了 (2认同)

Kam*_*ean 7

不需要删除所有node_modules文件夹。只要更新包:vuevue-template-compilervue-server-renderer通过@latest标记,它应该帮助与VUE包dismatched版本的任何情况。

npm i vue-template-compiler@latest --save

npm i vue-server-renderer@latest --save

--save会自动更新package.json文件中的版本。@latest表示安装软件包的最新可用版本。如果您需要更新,vue请像上面示例中一样进行更新。

此外,您还可以随时检查通过命令更新的新版本:npm outdated。它显示了所有应该更新的软件包列表。

顺便说一句,npm update命令仅更新次要版本和修补程序版本,但是在您要更新主要版本时不可用。例如npm update将不会更新2.4.5=> 3.0.1,但是可以更新


Sky*_*ker 7

我运行以下命令: yarn global upgrade

这将升级任何需要升级的关系


Man*_*ash 6

在这里,vue 模板编译器编译 vue 模板。如果你使用 vue 一个版本而 vue-template-compiler 另一个版本,那就是一个问题。

运行这个命令

npm update vue-template-compiler
Run Code Online (Sandbox Code Playgroud)

这将解决这个问题,它会安装一个与 vue js 版本相同版本的 vue 模板编译器。


All*_*rku 6

运行以下命令对我有帮助

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软件包版本不匹配错误修复


Cri*_*s19 6

更新 Vue 是我的解决方案。

npm i vue@latest --save
Run Code Online (Sandbox Code Playgroud)

想提一下,之前我执行了Kamil' Ocean回答中描述的步骤:

npm i vue-template-compiler@latest --save

npm i vue-server-renderer@latest --save
Run Code Online (Sandbox Code Playgroud)

更新 Vue 后,它就起作用了。

  • 最好的答案在这里。 (2认同)

小智 6

这些步骤帮助了我:

rm package-lock.json, rm -rf node_modules, npm update, npm install
Run Code Online (Sandbox Code Playgroud)


小智 6

这对我和你的 100% 有用:

  1. 修改package.json: "vue": "^2.6.12" 为 "vue": "2.6.12"
  2. 删除文件夹node_modules
  3. 删除package-lock.json
  4. 运行 npm 安装


Bho*_*yar 5

检查依赖关系vue并替换为精确的开发依赖关系vue-template-compiler

例如。

"dependencies": {
    "vue": "^2.5.2",
},
"devDependencies": {
    "vue-template-compiler": "^2.5.3",
},
Run Code Online (Sandbox Code Playgroud)

应替换为:

"dependencies": {
    "vue": "2.5.2",
},
"devDependencies": {
    "vue-template-compiler": "2.5.2",
},
Run Code Online (Sandbox Code Playgroud)

npm install再次运行。

  • 这就是我的解决方案。vue 和 vue-template-compiler 的版本相同,并且没有前导 ^ (2认同)