Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid value used as weak map key #335

Open
perryhong opened this issue Dec 14, 2021 · 0 comments
Open

TypeError: Invalid value used as weak map key #335

perryhong opened this issue Dec 14, 2021 · 0 comments

Comments

@perryhong
Copy link

perryhong commented Dec 14, 2021

版本:
"@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
}
]
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant