-
-
Notifications
You must be signed in to change notification settings - Fork 5k
vue ssr document is not defined #2380
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
Comments
Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you! 你好,你的 issue 不符合我们所要求的格式,因此已被自动关闭。为了确保每个 issue 都提供必需的相关信息,请务必使用我们的 Issue 向导 来创建新 issue,谢谢! |
I also had the same problem, I found it might be caused by mini-css-extract-plugin. So what I did to solve it is drop the css file at server render. const merge = require('webpack-merge')
const nodeExternals = require('webpack-node-externals')
const baseConfig = require('./webpack.base.config.js')
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
module.exports = merge(baseConfig, {
entry: './src/entry-server.js',
target: 'node',
devtool: 'source-map',
output: {
libraryTarget: 'commonjs2'
},
externals: nodeExternals({
whitelist: /\.css$/
}),
plugins: [
new VueSSRServerPlugin()
],
module: {
rules: [{
test: /\.css$/,
use: [
'css-loader/locals'
]
}, {
test: /\.scss$/,
use: [
'css-loader/locals',
'sass-loader'
]
}]
}
}) note Hope that will help you. Reference webpack-contrib/mini-css-extract-plugin#90 |
For me, I got a very similar error (with The fix was I was refreshing my babel config and took out |
use extract-css-chunks-webpack-plugin instead mini-css-extract-plugin webpack.base.config.js const ExtractCssChunksPlugin = require('extract-css-chunks-webpack-plugin')
{
...
{
test: /\.css$/,
use: [
{
loader: ExtractCssChunksPlugin.loader,
options: {
hot: !isProd,
reloadAll: !isProd
}
},
'postcss-loader',
'css-loader'
]
},
{
test: /\.less$/,
use: [
{
loader: ExtractCssChunksPlugin.loader,
options: {
hot: !isProd,
reloadAll: !isProd
}
},
'css-loader',
'postcss-loader',
'less-loader'
]
}
...
plugins: [
...
new ExtractCssChunksPlugin({
filename: isProd ? 'css/[name].[contenthash:8].css' : '[name].css',
chunkFilename: isProd ? 'css/[name].[contenthash:8].chunk.css' : '[name].chunk.css'
})
]
} webpack.server.config.js {
...
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
]
} |
Hello, in the version of vue-cli3+, how to use css-loader/locals? |
@lycHub Hello, I build SSR with webpack, I do not have any examples with vue-cli3 PS: I do have one, but it is "hybrid", SSR is still handled by webpack |
Hi, I am running into the same problem. However, i attempted to add your solution into my
i get the following error
|
I create a vue-ssr-demo project with vue-cli, and I also encountered the same problem. My solution is replace the mini-css-extract-plugin with a new loader // css-loader mini-css-extract-plugin(extract-css-loader),will generate browser sentence such as document.getElementsByTagName xxxxx。
// this will result in error (document not defined), running on server side。
// so delete mini-css-extract-plugin and replace with css-context-loader。
const langs = ['css', 'less']
const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
langs.forEach(lang => {
types.forEach(type => {
const rule = config.module.rule(lang).oneOf(type)
rule.uses.delete('extract-css-loader')
rule.use('css-context-loader').loader(CssContextLoader).before('css-loader')
})
}) the new loader you can reference vue-cli-plugin-ssr |
Hi everyone, I am trying to do server side render by 'vue-server-renderer', I can do
to develop, but when I try
I always got errors like this
my server.js looks like this
The text was updated successfully, but these errors were encountered: