vue-server-renderer 要和 vue 的版本一致,否则报错
add at 2022.02.19
我采用下面命令安装了 vue-server-renderer
和 vue
yarn add vue-server-renderer vue
- 因为没有指定版本,所有安装的版本是默认的
"dependencies": {
"express": "^4.17.3",
"vue": "^3.2.31",
"vue-router": "^4.0.12",
"vue-server-renderer": "^2.6.14"
}
- 然后运行代码,报错
D:\repos_vue_ssr\ssr-demo>npm run server
> ssr-demo@1.0.0 server D:\repos_vue_ssr\ssr-demo
> node server.js
D:\repos_vue_ssr\ssr-demo\node_modules\vue-server-renderer\index.js:8
throw new Error(
^
Error:
Vue packages version mismatch:
- vue@3.2.31
- vue-server-renderer@2.6.14
This may cause things to work incorrectly. Make sure to use the same version for both.
at Object.<anonymous> (D:\repos_vue_ssr\ssr-demo\node_modules\vue-server-renderer\index.js:8:9)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (D:\repos_vue_ssr\ssr-demo\server.js:6:25)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ssr-demo@1.0.0 server: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ssr-demo@1.0.0 server script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! D:\repos\npm\npm_cache\_logs\2022-02-19T05_00_48_831Z-debug.log
D:\repos_vue_ssr\ssr-demo>
- 根据出错结果
Vue packages version mismatch
可以得出:是版本不一致导致的报错 - 采用下面的命令重新安装
yarn remove vue-server-renderer vue
yarn add vue@2.6.14 vue-server-renderer@2.6.14
- 重新安装后的版本如下:
"dependencies": {
"express": "^4.17.3",
"vue": "2.6.14",
"vue-router": "^4.0.12",
"vue-server-renderer": "2.6.14"
}
- 再启动服务,就没有报错信息了
End