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

Gatsby build fails due to server-side rendering localStorage error #39224

Open
2 tasks done
Amirbeek opened this issue Feb 5, 2025 · 0 comments
Open
2 tasks done

Gatsby build fails due to server-side rendering localStorage error #39224

Amirbeek opened this issue Feb 5, 2025 · 0 comments
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@Amirbeek
Copy link

Amirbeek commented Feb 5, 2025

Preliminary Checks

Description

I encountered an error when running gatsby build. I tried all the recommended solutions, but none of them helped. The issue seems to be related to server-side rendering (SSR) and localStorage.

Steps to Reproduce:

Run gatsby build
Observe the error related to localStorage
Expected Behavior:
The build should complete successfully without SSR-related localStorage issues.

Actual Behavior:
The build fails with an error mentioning localStorage, which is not available in the server-side environment.

Attempted Solutions:

Followed all suggested fixes in the documentation and community forums.
Ensured localStorage is only accessed on the client side.
Tried wrapping localStorage calls in useEffect.

Reproduction Link

https://github.com/Amirbeek/SEO-Gatsby-template

Steps to Reproduce

...

Expected Result

The gatsby build command should complete successfully without errors. The built site should function correctly, and there should be no issues related to localStorage during server-side rendering.

Actual Result

The gatsby build process fails with an error related to localStorage. Since localStorage is not available in the server-side environment, Gatsby throws an error during server-side rendering (SSR).

Environment

Gatsby Version: 5.14.1
Node.js Version: Run node -v to check
Operating System: Run uname -a (Linux/macOS) or systeminfo (Windows) to check

Config Flags

No response

@Amirbeek Amirbeek added the type: bug An issue or pull request relating to a bug in Gatsby label Feb 5, 2025
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant