ScrollLock dist missing window undefined check
See original GitHub issueWhile 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:
ErrorDetails : ReferenceError: window is not defined
at ./node_modules/react-select/dist/base/dist/react-select-cac0a5ae.browser.esm.js (server.min.js:117809:17) -> var canUseDOM = !!(window.document && window.document.createElement);
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!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:15
Top Results From Across the Web
Window is not defined in Next.js React app - Stack Overflow
Check if the window object exists or not and then follow the code along with it. function getSelectedAddress() { if (typeof window ===...
Read more >How to solve "window is not defined" errors in React and Next.js
First solution: typeof Because typeof won't try to evaluate "window", it will only try to get its type, in our case in Node....
Read more >Linux xterm command help and examples - Computer Hope
If no shell is specified, and the SHELL environment variable is undefined, xterm uses the Bourne Shell, /bin/sh.
Read more >JMP Help
The JMP Starter Window ... Find Missing Characters in Imported Data ... Data Table Scroll Lock, Set Scroll Lock Columns.
Read more >Chapter 18 - Automate the Boring Stuff with Python
On Windows, there are no other modules to install. ... run import pyautogui from the interactive shell and check for any error messages....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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… 😃
In the code, it looks like there is a check for
typeof window !== 'undefined'
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 solution
For those looking for a potential fix, here are there solutions:
I think we are going to go with option 1…
UPDATE!
I found the culprit. Looks like preconstruct js is replacing things quietly:
https://github.com/preconstruct/preconstruct/blob/master/packages/cli/src/build/rollup.ts#L137