Gatsby build error - window is not defined
See original GitHub issueBefore you start - checklist
- I followed instructions in documentation written for my React-PDF version
- I have checked if this bug is not already reported
- I have checked if an issue is not listed in Known issues
- If I have a problem with PDF rendering, I checked if my PDF renders properly in Mozilla Firefox
Description
I just updated react-pdf to version 5.0.0 and got error when using gatsby build
to build my project. I have no error when using version 4.2.0
Environment
- React-PDF version [e.g. 3.0.4]: 5.0.0
- React version [e.g. 16.3.0]: 16.12.0
Error Log
$ gatsby build
success open and validate gatsby-configs - 0.041s
success load plugins - 1.130s
success onPreInit - 0.005s
success delete html and css files from previous builds - 0.013s
success initialize cache - 0.008s
success copy gatsby files - 0.149s
success onPreBootstrap - 0.022s
success createSchemaCustomization - 0.010s
success source and transform nodes - 1.134s
success building schema - 0.300s
success createPages - 0.388s
success createPagesStatefully - 0.087s
success updating schema - 0.052s
success onPreExtractQueries - 0.003s
success extract queries from components - 0.769s
success write out requires - 0.008s
success write out redirect data - 0.003s
success onPostBootstrap - 0.010s
info bootstrap finished - 7.579s
success Downloading remote files - 0.283s - 15/15 53.03/s
success run static queries - 0.589s - 3/3 5.09/s
success Building production JavaScript and CSS bundles - 11.826s
success Rewriting compilation hashes - 0.008s
success run page queries - 1.487s - 42/42 28.25/s
[============================] 13.962 s 31/31 100% Generating image thumbnails
[ ] 0.001 s 0/42 0% Building static HTML for pages
(node:21076) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at C:\work\aavn-portal-workspace\packages\client\public\render-page.js:19640:3
at new Promise (<anonymous>)
at Object.../../node_modules/pdfjs-dist/lib/web/ui_utils.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:19639:26)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
at Object.../../node_modules/pdfjs-dist/lib/web/pdf_link_service.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:18639:17)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
at Module.../../node_modules/react-pdf/dist/esm/LinkService.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:22670:93)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
at Module.../../node_modules/react-pdf/dist/esm/Document.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:22109:71)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
at Module.../../node_modules/react-pdf/dist/esm/entry.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:25120:67)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
at Module../src/components/ReaderPage/PDFReader/index.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:29742:67)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
at Module../src/components/ReaderPage/index.js (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:29764:68)
at __webpack_require__ (C:\work\aavn-portal-workspace\packages\client\public\render-page.js:30:30)
(node:21076) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To tesuccess Building static HTML for pages - 2.369s - 42/42 17.73/s
success Generating image thumbnails - 16.344s - 31/31 1.90/s
success onPostBuild - 0.009s
info Done building in 24.2845958 sec
Done in 24.55s.
Done in 24.86s.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Gatsby - the window is not defined error, what and how to fix it?
You can check if the browser-global object window is defined and based on it, execute the related code block. ... The variable isBrowser...
Read more >Error when building Gatsby website: window is not defined
!== 'undefined' condition. Essentially, this is because gatsby build occurs in the server, where there's no window (or other global objects such ...
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 >Debugging HTML Builds | Gatsby
js. If this is your problem you should see an error above like “window is not defined”. To fix this, find the offending...
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 >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
It happens also without Gatsby when running SSR on nodejs:
All, please kindly help me with testing the fix for this issue. ➡️ https://github.com/wojtekmaj/react-pdf/issues/748
Thanks!