WebpackError: ReferenceError: window is not defined
See original GitHub issueI am having irritative behaviour with my gatsby build. I can successfully run the development build using npm start
but when I use to run it in production mode using gatsby build
I am getting below error
error Building static HTML failed for path "/application/"
See our docs page on debugging HTML builds for help https://gatsby.app/debug-html
6097 |
6098 | function getLocaleObject(localeName) {
> 6099 | return window.__localeData__ ? window.__localeData__[localeName] : null;
| ^
6100 | }
6101 |
6102 | function getFormattedWeekdayInLocale(date, formatFunc, locale) {
WebpackError: ReferenceError: window is not defined
- index.js:6099 getLocaleObject
[lib]/[react-datepicker]/es/index.js:6099:1
- index.js:5973 formatDate
[lib]/[react-datepicker]/es/index.js:5973:1
- index.js:5990 safeDateFormat
[lib]/[react-datepicker]/es/index.js:5990:1
- index.js:8822 DatePicker._this.renderDateInput
[lib]/[react-datepicker]/es/index.js:8822:1
- index.js:8900 DatePicker.render
[lib]/[react-datepicker]/es/index.js:8900:1
- bootstrap:19 c
lib/webpack/bootstrap:19:1
- bootstrap:25 a.render
lib/webpack/bootstrap:25:1
- bootstrap:24 a.read
lib/webpack/bootstrap:24:1
- bootstrap:36 renderToString
lib/webpack/bootstrap:36:1
- static-entry.js:194 Module../.cache/static-entry.js.__webpack_exports__.defa ult
lib/.cache/static-entry.js:194:18
- bootstrap:24 Promise
lib/webpack/bootstrap:24:1
- gatsby-browser-entry.js:2 Promise._resolveFromExecutor
lib/.cache/gatsby-browser-entry.js:2:1
- bootstrap:68 new Promise
lib/webpack/bootstrap:68:1
Can someone please help why I am getting this error. Thank you!!!
Issue Analytics
- State:
- Created 5 years ago
- Comments:21
Top Results From Across the Web
Gatsby - the window is not defined error, what and how to fix it?
The nodejs environment doesn't have the browser-globals like window , document , etc. Hence if the source code has a reference to them,...
Read more >Window is not defined · Issue #309 · gatsbyjs/gatsby - GitHub
Works fine in development but if I try to gatsby build , I get Error: ReferenceError: window is not defined . I'm doing...
Read more >WebpackError: ReferenceError: window is not defined on Gatsby
When using third-party dependencies (such as your Bootstrap modal) your capability to access to window object disappears.
Read more >ReferenceError: Window Is Not Defined in GatsbyJS
Debugging why your GatsbyJS (or NextJS) build is failing when you receive the message 'window is not defined'.
Read more >How To Solve ReferenceError window is not defined in ...
If you are specifically working on a Node.js application and still receive this error, it is because the window object does not actually...
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 Free
Top 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
Well I have found a solution.
Go to
node_modules/react-datepicker/es/index.js
and define thewindow
variablevar window = require('window')
No I think it would be a dirty fix, the root cause should be fixed. I think the problem here, is that it’s behaving in a different way than
date-fns
.The
date-fns
library does not have any global configuration, it lets the user handle a configuration object.react-datepicker
keeps a global configuration object whereas it should provide a similar way to configure it than date-fns. By doing it this way, it would remove the need for any globalwindow
usage.Could there be a way to do it this way?