-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Trouble with SSR and splitChunks - window is not defined #2270
Comments
I would create a ticket in the ReactOnRails repo. SSR is outside of webpacker's scope. |
I haven't used the Webpacker configuration much so don't know the exact syntax (currently using webpack manually without webpacker integration), but it is most likely that you need to set output.globalObject = 'this' in the Webpack configuration ( https://webpack.js.org/configuration/output/#outputglobalobject
|
@smgilchrist Did you find a solution? |
@smgilchrist I'm running into a similar issue when I use the cacheGroups option.
Try removing that part and see if it works for you. But if you got it to work, please share your solution! :) |
Also @smgilchrist, check out this solution from this link: reactjs/react-rails#970 (comment) // We have two entry points, application and server_rendering.
// We always want to keep server_rendering intact, and must
// exclude it from being chunked.
const notServerRendering = name => name !== 'server_rendering';
module.exports = {
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks(chunk) {
return notServerRendering(chunk.name);
}
}
}
}
}
} This worked for me. |
I have an updated version of that snippet to also create a separate But I haven't had any luck trying to do what the original poster is doing, where // We have two entry points, application and server_rendering.
// We always want to keep server_rendering intact, and must
// exclude it from being chunked.
const notServerRendering = name => name !== 'server_rendering';
module.exports = {
optimization: {
splitChunks: {
chunks(chunk) {
return notServerRendering(chunk.name);
},
cacheGroups: {
vendor: {
name: 'vendor',
priority: -10,
test: /[\\/]node_modules[\\/]/
},
vendor_react: {
name: 'vendor_react',
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/
}
}
}
}
}; <%= javascript_pack_tag "vendor_react.js", defer: true %>
<%= javascript_pack_tag "vendor.js", defer: true %>
<%= javascript_pack_tag "application.js", defer: true %> |
We wanted to have multiple entrypoints (beyond just
|
Can this issue be closed? |
I am currently trying to upgrade webpacker so that we can move from webpack 3 to 4. One of the big changes is changing from CommonsChunkPlugin to splitChunks, and then using javascript_packs_with_chunks_tag instead of javascript_pack_tag.
This is the set up of our current environment.js
Here is an example of one of the packs we load:
Here is a snippet from public:
The splitChunks seem to be working as expected, and the app works as intended when I turn server side rendering off for all the react components, but when I turn the server side rendering on, I keep getting a window is not defined error.
I've tried a couple suggestions on how turn OFF splitChunks for server side rendering only, but the results ended up with splitChunks being turned off for both server side and client side.
Please let me know if there is anything else I should include in this, but essentially I am trying to find a solution to not use splitChunks when it's server side.
The text was updated successfully, but these errors were encountered: