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

fail fast/eslint plugin that checks for window #12769

Closed
kentcdodds opened this issue Mar 22, 2019 · 5 comments
Closed

fail fast/eslint plugin that checks for window #12769

kentcdodds opened this issue Mar 22, 2019 · 5 comments
Labels
help wanted Issue with a clear description that the community can help with.

Comments

@kentcdodds
Copy link
Contributor

Summary

I wish I could say I never make this mistake, but I make it pretty often. The error message I get when building is:

error Building static HTML failed for path "/workshops/asynchronous-java-script"
See our docs page on debugging HTML builds for help https://gatsby.app/debug-html
  11 |   const {event, discount} = props
  12 |   const [titoWidgetReady, setWidgetReady] = React.useState(
> 13 |     window.hasOwnProperty('TitoWidget'),
     |     ^
  14 |   )
  15 |
  16 |   React.useEffect(() => {

  WebpackError: ReferenceError: window is not defined

The problem is I'm referencing window in the render method. This works fine in dev, but it doesn't work when running gatsby build.

Motivation

I know that it's my problem. But it'd be cool if gatsby develop would give me a warning if it detected something that wont work for the build. There could be other situations, but I know that at least referencing browser-only globals in the render method doesn't work during the build but works during develop and I don't realize something's wrong until it breaks in CI.

So I'd really appreciate some sort of gatsby eslint plugin (like suggested in #7687) or (even better) an error in develop for anything that would fail in build.

@DSchau
Copy link
Contributor

DSchau commented Mar 25, 2019

@kentcdodds this would be super slick, and agreed, I've seen people suffer through a broken build while they iron out usages of globals in SSR environment.

Giving actionable feedback prior to failing in build is key here. I've never written an eslint plugin, but this certainly seems like something that could be doable--so we'll take a look and prioritize appropriately!

Thanks for the idea!

@sidharthachatterjee
Copy link
Contributor

Watching jsx-eslint/eslint-plugin-react#2057 closely

@gatsbot
Copy link

gatsbot bot commented May 1, 2019

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

Thanks for being a part of the Gatsby community! 💪💜

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label May 1, 2019
@gatsbot
Copy link

gatsbot bot commented May 12, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

@gatsbot gatsbot bot closed this as completed May 12, 2019
@sidharthachatterjee sidharthachatterjee added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Jul 1, 2019
@LekoArts LekoArts added the help wanted Issue with a clear description that the community can help with. label May 25, 2020
@LekoArts
Copy link
Contributor

LekoArts commented Mar 1, 2021

We have solved this with SSR in Development now: #28138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with.
Projects
None yet
Development

No branches or pull requests

5 participants