Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: window is not defined #39

Open
RayonDabre opened this issue Jan 16, 2020 · 5 comments
Open

ReferenceError: window is not defined #39

RayonDabre opened this issue Jan 16, 2020 · 5 comments

Comments

@RayonDabre
Copy link

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

@bsdfzzzy
Copy link
Owner

Why not give a mock window object when in SSR.

@RayonDabre
Copy link
Author

@bsdfzzzy Any suggestion on this? Hammer.js also uses document, not sure how to spoof that.

@bsdfzzzy
Copy link
Owner

Many third partern use window or document. So you should set default mock window and mock document and even more mock object to make it work. I remember Mozilla has an open source library to solve these issues. You can try to find it out.

@iancleary
Copy link

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 😊

@sebj54
Copy link

sebj54 commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants