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

getGatsbyImageData Unhandled Runtime Error #204

Open
paulwhitaker opened this issue Dec 6, 2022 · 2 comments
Open

getGatsbyImageData Unhandled Runtime Error #204

paulwhitaker opened this issue Dec 6, 2022 · 2 comments

Comments

@paulwhitaker
Copy link

paulwhitaker commented Dec 6, 2022

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

@paulwhitaker
Copy link
Author

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.

@jaska120
Copy link

jaska120 commented Mar 3, 2023

I tried to debug this without luck. Did anybody find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants