-
-
Notifications
You must be signed in to change notification settings - Fork 384
Async loading without document context throws errors #48
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
@ctbarna Thanks for issue. Can you create minimum reproducible test repo? |
I can give it a shot but I will admit that I am not well versed in bootstrapping an SSR repo. The gist of the issue is that this creates a browser dependency in the webpack |
@ctbarna without reproducible test repo very difficult find problem 😞 |
I had the same issue. If I'm not mistaken, the plugin uses Here is a solution: Bundle your app for the client and additionally bundle your app for the server. When bundling for the server don't use mini-css-extract-plugin. Instead you use When you bundle the client, create a I hope that helped. |
|
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
})
]
} |
I'm trying to get mini-css-extract-plugin to play nicely with react-loadable on the server. Everything seems relatively easy except that when I run
Loadable.preloadAll()
on the server,requireEnsure
gets called for every async chunk. If the async chunk has CSS that hasn't been loaded it tries to insert a new link element, aReferenceError: document is not defined
gets thrown.The text was updated successfully, but these errors were encountered: