Open hirenoble opened 3 years ago
Hi @hirenoble!
I tried Googling that specific Gatsby error and found this SO thread: https://stackoverflow.com/a/64313153
If you tweak your webpack config as suggested in the accepted answer, does that fix anything? Also, what happens if you try gatsby develop
instead of gatsby build
?
Hey all 👋 greatly appreciate this library, v cool that Stoplight supports this in any capacity.
Edit from previous post: I found one of your examples outlining a similar approach.
For anyone seeing this trying to integrate with Next.js or similar frameworks that require server-side/non-browser rendering, try this when instantiating the libraries in this repo 👍
router={typeof window === 'undefined' ? 'memory' : 'history'}
Thank you @estrattonbailey I was trying to implement elements in a brand new next.js project and this solved my issue. Here is the final code
import Head from "next/head";
import { API } from "@stoplight/elements";
import "@stoplight/elements/styles.min.css";
export default function Home() {
return (
<div>
<Head>
<title>Example API</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<API
apiDescriptionUrl="https://raw.githubusercontent.com/stoplightio/Public-APIs/master/reference/zoom/openapi.yaml"
router={typeof window === "undefined" ? "memory" : "history"}
/>
</div>
);
}
The Gatsby build fails as there is no "window" component on server side rendering.
A clear and concise description of what the bug is.
To Reproduce
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
Screenshots If applicable, add screenshots to help explain your problem.
Environment (remove any that are not applicable):