question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: window is not defined

See original GitHub issue

In the contest of SSR, getting error as ReferenceError: window is not defined. Any suggestion to make it SSR compatible?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
sebj54commented, Mar 11, 2020

I also use Gridsome and encountered this issue.

You’ll find the solution I found below. In your main.js file:

export default function(Vue, { isClient }) {
    if (isClient) {
        const { VueHammer } = require('vue2-hammer')
        Vue.use(VueHammer)
    }
}

@bsdfzzzy Mocking document or window 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.

0reactions
ianclearycommented, Jan 26, 2020

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 packages null-loader and others to try to patch how hammerjs 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 the hammerjs dependency allows vue2-touch-events to build properly. I’m making an assumption that is a similar application to SSR, so please

I hope that helps.

@bsdfzzzy For non SSR applications, I really enjoyed the little time I spent with vue2-hammer when I was just doing local live development with yarn develop. Thank you 😊

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found