gatsby-source-sanity
gatsby-source-sanity copied to clipboard
getGatsbyImageData Unhandled Runtime Error
- Gatsby 5
- Gatsby Source Sanity 7.5.1
- Typescript
- NodeJS 18.12.1
I'm using getGatsbyImageData because the _rawContent query doesn't return the GatsbyImageData node. (Which seems odd). Until recently, this hasn't been an issue. Now, however, I am getting the following error in the browser.
One unhandled runtime error found in your files. See the list below to fix it:
Error in function eval in ./node_modules/gatsby-source-sanity/lib-es5/images/getGatsbyImageProps.js:
exports is not defined
./node_modules/gatsby-source-sanity/lib-es5/images/getGatsbyImageProps.js:
Open in Editor
No codeFrame could be generated
Here is an example of how this is implemented in my code...
...
import { getGatsbyImageData } from "gatsby-source-sanity"
const BackgroundImage = (props:any) => {
const sanityConfig: any = {
projectId: process.env.GATSBY_SANITY_PROJECT_ID,
dataset: process.env.GATSBY_SANITY_DATASET,
}
...
const {
alt = "Background Image",
backgroundImageType = "cover",
asset: { id: imageAssetID, url } = { id: null, url: undefined}
} = imageObject
...
<GatsbyImage
image={getGatsbyImageData(imageAssetID,{},sanityConfig)}
alt={alt}
className="section-background-image-cover"
/>
...
}
export default BackgroundImage
What is strange is that if I run 'gatsby develop' enough times, this eventually runs correctly. After that if I run 'gatsby clean', then the problem starts again until it finally builds correctly and then runs again. If it helps, this doesn't seem to occur whenever you run 'gatsby build'
I'm completely stumped. Any help would be appreciated.
I spent two days removing getGatsbyImageData from my code base to get around this error. I would still like to know if this was something I did wrong, of if there was a bug.
I tried to debug this without luck. Did anybody find a solution?