vuejs/vue2-ssr-docs

TypeError: Invalid value used as weak map key

perryhong opened this issue · 0 comments

版本:
"@vue/server-renderer": "^3.2.26",
"express": "^4.17.1",
"vue": "^3.2.26"

webpack 打包后启动服务访问时会报错
(node:43480) UnhandledPromiseRejectionWarning: TypeError: Invalid value used as weak map key
at WeakMap.set ()
at En (/Users/perry.hong/code/vue-ssr-demo/dist/server/index.js:1:86749)
at Zo (/Users/perry.hong/code/vue-ssr-demo/dist/server/index.js:1:113862)
at h (/Users/perry.hong/code/vue-ssr-demo/dist/server/index.js:1:157156)
at /Users/perry.hong/code/vue-ssr-demo/dist/server/index.js:1:160697
at /Users/perry.hong/code/vue-ssr-demo/dist/server/index.js:1:160729
at renderComponentSubTree (/Users/perry.hong/code/vue-ssr-demo/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:263:13)
at renderComponentVNode (/Users/perry.hong/code/vue-ssr-demo/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:214:16)
at /Users/perry.hong/code/vue-ssr-demo/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:456:30
at Generator.next ()

如果在app.vue引入子组件注册,服务端rendertostring就会报错
App.vue的components注册MyUser子组件,引入。

webpack简单配置
`const HtmlWebpackPlugin = require('html-webpack-plugin');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const path = require('path');

const commonConfig = {
cache: false,
resolve: {
extensions: ['.vue', '.js', '.json', '.wasm'],
},
module: {
rules: [{
test: /.vue$/,
use: [
{
loader: 'vue-loader',
options: {
compilerOptions: {
preserveWhitespace: false
}
}
}
]
}, {
test: /.js$/,
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env'
],
},
exclude: /node_modules/
}]
}
}

module.exports = [
{
entry: './src/entry_client.js',
output: {
filename: "index.js",
path: path.join(__dirname, 'dist/client')
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html"
}),
new VueLoaderPlugin()
],
...commonConfig
},
{
target: "node",
entry: './src/entry_server.js',
output: {
filename: "index.js",
path: path.join(__dirname, 'dist/server'),
libraryTarget: 'commonjs2'
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html"
}),
new WebpackManifestPlugin({
filename: './ssr-manifest.json'
}),
new VueLoaderPlugin()
],
...commonConfig
}
]
`