Gatsby error with useRef only when deploying

I’m trying to deploy a Gatsby site that is working perfectly on local host. But once trying to deploy, it throws the below error. I’m using a global context (defined in a separate js file, and referred to in both gatsby-browser.js and gatsby-ssr.js) to provide any component with important global variables/ functions. In this case, I’m trying to use a useRef in a sub-component but it’s saying that the useRef’s .current is ‘undefined’. Without providing more context, why would this all work like a charm on local host, but throw such an error during deployment?

A bit more context actually: I followed this approach to share state across components and, as said, it worked perfectly while on local hosts…

Hey there, @BenMan :wave:

Hiya, sorry you are having trouble with your build.

This Support Guide contains a ton of useful debugging tips that can likely help you solve your problem :slight_smile: Additionally, this Support Guide houses all of our resources for debugging build and deploy issues.

We also recommend trying to search the forums with the build error you encountered - it’s likely your question was already asked by someone else!

If you are still having problems, please provide as much information as you can on what you have already tried, what your build settings are, your package.json, a link to your netlify site, etc. Thanks!

Thank you for providing these resources. I had to move my attention to another project for the time being. One hunch is that possibly I forgot to clarify ‘gatsby develop’ as a build command when deploying in Netlify, but not sure.

Hey there, @BenMan :wave:

Thanks for coming back and letting us know. Good luck with your next project :raised_hands: we will be here if you have further questions.