-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
ScrollLock dist missing window undefined check #3802
Comments
@swensorm Have you found any solution? |
I have a workaround in place for the time being, but it's really not ideal as it renders nothing server side so there's a delay to it appearing in the browser. The exception would be thrown just from the static import, since the offending code isn't part of the component, so I have to dynamically require it. if (typeof window === 'undefined') {
return null;
}
const { default: Select, components } = require('react-select'); // eslint-disable-line global-require |
The bundle you use on the server should be built with webpacks target: 'node' to resolve modules from 'main' or 'module' fields and not using client-side specific aliases. Since you're not running it under nodejs (ReactJS.NET does not provide full nodejs environment) you will get "require is not defined" when trying to use bundle built like this but there is away. In the server build, keep target: 'web' (default when unspecified) but change resolve.aliasFields to an empty array, like this:
This way webpack will not use browser specific aliases when resolving react-select module... Ufff... :) |
I was able to solve a similar issue with "window is not defined" when using SSR with reactjs.net by using your fix @mgrzyb . |
While I can confirm that adding |
Same :) |
Why can't you check if windows is defined on canUseDOM() function?
|
In the code, it looks like there is a check for However, in the compiled version I see:
Manually updating that code fixes the issue. Why does the code in the git repo differ from the built version on NPM? Potential solutionFor those looking for a potential fix, here are there solutions:
{
resolve: {
alias: {
"react-select": require.resolve(
"react-select/dist/react-select.cjs.prod.js"
),
},
},
} I think we are going to go with option 1... UPDATE!I found the culprit. Looks like preconstruct js is replacing things quietly: |
Any headway on this? the alias and aliasFields method did not work for me when trying to upgrade to react-select 3.1.1. Still getting the
when trying to SSR |
Good news everyone! Looks like this behavior in I will inquire about getting its dependency updated from 1.0 to 2.0.2 to resolve this as well as any other changes that might be required. |
@mgrzyb's comment hits at the root issue and provides the best solution at the moment. See reactjs/React.NET#1017 for more context. I don't believe that the fix to Preconstruct affects this issue because that fix is specific for UMD builds, and this issue is specific to non-UMD builds. Preconstruct is intentionally and correctly stripping I'm going to close this for now. I don't believe that there's anything else that |
I'll leave this open until a permanent solution is found for purposes of visibility. |
I do not agree with the assessment that the runtime environment not supporting a It has been some time since I was in these codebases, and we're on a pretty old version, so perhaps just need to take another look at the build and split ssr from client or, as @ianks suggested, see if the non-browser cjs version works. |
@swensorm I am in general agreement with what you're saying although I would have to do some further investigation into the issue to form a stronger opinion. I don't think that the root issue is Precontruct, I think it has more to do with not having a way to express which file can/should be used for SSR. I've made a PR to remove the browser alias fields since they provide no real benefit in our case. |
I've done some more research. Even if we remove the browser alias fields for If we are able to do anything on our end that would fix the problem, we would do it, but at this point Emotion would need to change first (which doesn't seem likely given the above issues). |
While attempting to upgrade react-select from version 2.4.4 to the latest 3.0.8 I'm running into issues with server side rendering and the following error:
We use this within a .Net CMS by way of ReactJS.Net so the
window
object is not available while it is being rendered on the server. The strange thing is that looking at the dist output from the npm package, the check for window being undefined isn't there:However, looking at the src it is:
The check did exist in the dist output of the 2.4.4 version so something with the build process may have been changed with version 3.0.0 that could have caused this? Thank you for looking at the issue!
The text was updated successfully, but these errors were encountered: