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.

Gatsby static HTML build fails due to dependency on browser API AbortController

See original GitHub issue

The problem I’ve recently ported my personal site into a Gatsby application to try it out. I love restful-react, but I’ve hit an issue where the Gatsby static HTML build fails due to restful-react hooks depending on AbortController at the point when the hook is run, rather than when the HTTP request is made. Gatsby suggest any interactions with browser APIs be run inside a useEffect so that they run when the browser binds to React, rather than at build time. However, this is happing in a hook so I cannot move it to inside a useEffect as it breaks the rules of hooks!

Potential solution Haven’t looked at the restful-react source code yet but it seems like creating an instance of AbortController is being done prematurely and should be done at the time of calling the mutate function exposed by useMutate, for example, rather than when useMutate is first run.

Alternative solutions

  • Allow the restful-react hooks to be fired in a ‘mock’ way, which stubs them when not running in the browser. Not sure I think this is a good solution though, but would avoid any server-side issues.
  • Only allow AbortController and other browser APIs to run in the browser, but still allow the fetching of data without that added functionality when running in a non-browser environment?

Example usage image

Link to Gatsby docs https://www.gatsbyjs.org/docs/debugging-html-builds/

Output of Gatsby build error

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fabien0102commented, Mar 22, 2020

Fixed! Thanks to @mbrookson 😘

1reaction
mbrooksoncommented, Mar 8, 2020

All I did was fork master, run yarn and run yarn build 🙁

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging HTML Builds | Gatsby
Errors while building static HTML files (the build-time React SSR process) or while using getServerData (the runtime SSR process…
Read more >
Gatsby 3 – `gatsby build` fails on 'Building static HTML for ...
I've updated all relevant packages to the current versions and have no relevant dependency errors or outdated packages. If any other context is ......
Read more >
Compare Versions | @brainhubeu/gatsby-docs-kit | npm
We found errors while resolving dependencies that may result in an incomplete or inaccurate dependency graph. Show details. Errors found while resolving some ......
Read more >
[Gatsby] Building static HTML failed for path - Support
There is an error when trying to build the website, the weird thing is that this is only happening in netlify, when I...
Read more >
search | /*code-comments*/
... brian mccullough (1) · browser api (2) · browser security (1) · browser support (1) · browsers (1) · bst (1) ·...
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