Upgrading Gatsby Project to V3 - Attempted import error: 'getFluidGatsbyImage' is not exported

1 replies
Last updated: Mar 19, 2021
Hey everyone, I’m trying to upgrade a Gatsby project to V3 and get this error when trying to load fluid images from inside my Richtext renderer. I’m using the serializer for type “figure” and query the Sanity images using this snippet…
import React from "react"
import Img from "gatsby-image"
import { getFluidGatsbyImage } from "gatsby-source-sanity"
import * as css from "./figure.module.css"

const Figure = ({ node }) => {
  const fluidProps = getFluidGatsbyImage(
    node.image.asset._ref,
    { maxWidth: 1024 },
    {
      projectId: process.env.SANITY_PROJECT_ID || "bjzgdow4",
      dataset: process.env.SANITY_DATASET || "production",
    }
  )

  return (
    <figure className={`css.root my-6`}>
      <Img fluid={fluidProps} alt={node.alt} />
      {node.caption && (
        <figcaption className={css.figcaption}>{node.caption}</figcaption>
      )}
    </figure>
  )
}

export default Figure
Unfortunately, I get this error now in V3?

warn Attempted import error: 'getFluidGatsbyImage' is not exported from 'gatsby-source-sanity' (imported as 'getFluidGatsbyImage').
Thanks – any inputs and help much appreciated
🙂
AI Update

Hey! This is a known breaking change with Gatsby v3 and the gatsby-source-sanity plugin. The getFluidGatsbyImage and getFixedGatsbyImage helper functions were removed because Gatsby v3 deprecated the old gatsby-image package in favor of the new gatsby-plugin-image.

Here's how to fix your code:

1. Install the new image plugin:

npm install gatsby-plugin-image

2. Update your imports and code:

import React from "react"
import { GatsbyImage } from "gatsby-plugin-image"
import { getGatsbyImageData } from "gatsby-source-sanity"
import * as css from "./figure.module.css"

const Figure = ({ node }) => {
  const imageData = getGatsbyImageData(
    node.image.asset._ref,
    { maxWidth: 1024 },
    {
      projectId: process.env.SANITY_PROJECT_ID || "bjzgdow4",
      dataset: process.env.SANITY_DATASET || "production",
    }
  )

  return (
    <figure className={`css.root my-6`}>
      <GatsbyImage image={imageData} alt={node.alt} />
      {node.caption && (
        <figcaption className={css.figcaption}>{node.caption}</figcaption>
      )}
    </figure>
  )
}

export default Figure

Key changes:

  • getFluidGatsbyImagegetGatsbyImageData
  • gatsby-imagegatsby-plugin-image
  • Img component → GatsbyImage component
  • fluid prop → image prop

The new getGatsbyImageData helper works similarly but returns data compatible with the modern GatsbyImage component. The gatsby-source-sanity plugin documentation should have more details on the image helper functions available.

This migration is part of Gatsby's move to a more performant image handling system with better lazy loading and modern image formats support. Your images should work even better after this change! 🎉

Oh silly me, never mind. This is all well documented in the migration path here . Thanks Sanity!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?