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

Eexpects window to be defined, but now always the case #9

Closed
jslyonnais opened this issue Oct 19, 2018 · 3 comments
Closed

Eexpects window to be defined, but now always the case #9

jslyonnais opened this issue Oct 19, 2018 · 3 comments

Comments

@jslyonnais
Copy link

Webpack production build using Gatsby return WebpackError: ReferenceError: window is not defined.
Should make sure window is define before loading intersection-oberver. Will also make other window usage in scrollama.js works with that mechanic.

@NicholasLYang
Copy link
Contributor

Just clarifying, this is code executed by the browser, correct? Because Gatsby is a server side renderer, so if you're rendering on node, window won't be defined. Just want to make sure we're on the same page.

@jslyonnais
Copy link
Author

jslyonnais commented Oct 24, 2018

Finally found a workaround.
You got right about Gatsby, but I was thinking if I can find a way to make things work.

Comment for futur people, finally I've use scrollama directly from npm, and call it on the componentDidMount of react.

componentDidMount() {
    // Loading module that require "window" to be defined
    require('intersection-observer')
    const scrollama = require('scrollama')

    const scrollThreshold = 0.33
    const scroller = scrollama()
    scroller.setup({
      // debug: true,
      step: '.scroll__step',
      threshold: scrollThreshold,
      container: '.scroll__container',
      graphic: '.scroll__graphic'
    }).onStepEnter(this.handleScrollStepEnter)
  }

@NicholasLYang
Copy link
Contributor

Great! Thanks for posting your solution.

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

2 participants