ReferenceError: window is not defined
See original GitHub issueIn the contest of SSR
, getting error as ReferenceError: window is not defined
.
Any suggestion to make it SSR compatible?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to solve "window is not defined" errors in React and Next.js
How to solve "window is not defined" errors in React and Next.js · 1. First solution: typeof · 2. Second solution: the useEffect...
Read more >How to solve Next.js window is not defined
ReferenceError: window is not defined is a pretty common error you may run into when using Next.js for the first time but don't...
Read more >referenceerror: window is not defined, how to solve
Here's how to fix the “referenceerror: window is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >How To Solve ReferenceError window is not defined in ...
Fixing a window is not defined error can be quite simple. In most cases, all you will need to do is wrap your...
Read more >[Solved] ReferenceError : window is not defined - ItsJavaScript
The ReferenceError : window is not defined error mainly occurs if you are using the window object in Node.js, React.js, Next.js.
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
I also use Gridsome and encountered this issue.
You’ll find the solution I found below. In your
main.js
file:@bsdfzzzy Mocking
document
orwindow
does not help (I tried) because hammerjs has its own scope when it is imported or required. Parent scope where you could mock such objects is not accessible.Hello @RayonDabre @bsdfzzzy,
I’m currently learning about Vue, Gridsome, and have been doing some searching trying to better handle touch events in a Gridsome application where I believe it’s build process behaves similar to
SSR
. I also wasn’t sure how to mock the different objects. I tried a few different loader packagesnull-loader
and others to try to patch howhammerjs
loads, but I didn’t get a solution.@RayonDabre I’m not familiar with what @bsdfzzzy was alluding to regarding Mozilla, but perhaps you can try using vue2-touch-events. I got
gridsome build
to work without any issues. From a brief comparison, it seems the lack of thehammerjs
dependency allowsvue2-touch-events
to build properly. I’m making an assumption that is a similar application toSSR
, so pleaseI hope that helps.
@bsdfzzzy For non
SSR
applications, I really enjoyed the little time I spent withvue2-hammer
when I was just doing local live development withyarn develop
. Thank you 😊