Skip to content

getGatsbyImageData Unhandled Runtime Error #204

@paulwhitaker

Description

@paulwhitaker
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions