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

Webpack: Generating HTML failed Error: ReferenceError: window is not defined #303

Closed
7 tasks done
Ognian opened this issue Mar 20, 2017 · 1 comment
Closed
7 tasks done

Comments

@Ognian
Copy link

Ognian commented Mar 20, 2017

Please make sure to check the following boxes before submitting an issue. Thanks!

  • All peer dependencies are installed: React, ReactDOM and Leaflet.
  • Using a supported version of React and ReactDOM (v15.0.0+).
  • Using the supported version of Leaflet (v1.0.0) and its corresponding CSS file is loaded.
  • Using the latest version of React-Leaflet.
  • The issue has not already been reported.
  • Make sure you have followed the quick start guide for Leaflet.
  • Make sure you have fully read the documentation and that you understand the technical considerations.

I'm using react-leaflet with gatsby, a static site generation framework. As long as I'm in development mode everything is ok, but as soon as I try to generate the static bundle webpack reports the following error:

Generating HTML failed Error: ReferenceError: window is not defined
    at Object.defineProperty.value (render-page.js:78978:4)
    at __webpack_require__ (render-page.js:30:30)
    at Object.L.version (render-page.js:65715:17)
    at __webpack_require__ (render-page.js:30:30)
    at Object.defineProperty.value (render-page.js:65665:17)
    at __webpack_require__ (render-page.js:30:30)
    at Object.defineProperty.value (render-page.js:65519:15)
    at __webpack_require__ (render-page.js:30:30)
    at Object.exports.__esModule (render-page.js:51672:22)
    at __webpack_require__ (render-page.js:30:30)

looks like this happens when you import leaflet
https://github.com/PaulLeCam/react-leaflet/blob/master/src/Map.js#L3
according to the react docs
using window is only allowed in componentDidMount() : "Initialization that requires DOM nodes should go here. "
Others seem to have the same problem:
webpack/react-starter#37
gatsbyjs/gatsby#309
and solved it by using require instead of import and doing this conditionally...

What do you think?
Thanks
Ognian

@Ognian
Copy link
Author

Ognian commented Mar 20, 2017

Sorry, understood this #45
to late, therefore I'm closing this issue. I understand that this will not change soon...

@Ognian Ognian closed this as completed Mar 20, 2017
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

1 participant