Discrepancy between local and production image URLs with @sanity/image-url
23 replies
Last updated: Jan 7, 2022
B
having a discrepancy between local and production regarding
here’s how i have things coded
imageUrl.js
config.js
component where image should output
any ideas why this doesn’t work on Gatsby Cloud?
@sanity/image-url. Works as expected locally, but when published to Gatsby Cloud, my image URLs have
/undefined/undefined/where the
projectIdand
datasetshould be.
here’s how i have things coded
imageUrl.js
import config from '../../config' import imageUrlBuilder from '@sanity/image-url' const builder = imageUrlBuilder(config.source) export function urlFor(incoming) { return builder.image(incoming) }
const Config = { source: { projectId: process.env.PROJECT_ID, dataset: process.env.DATASET, apiVersion: process.env.API_VERSION, }, } module.exports = Config
article.featuredImage && <img src={urlFor(article.featuredImage).width(300).height(500).url()}
Jan 7, 2022, 8:46 PM
B
even if its the same variables used elsewhere?
Jan 7, 2022, 8:52 PM
B
or i suppose not, since they are only used at build time
Jan 7, 2022, 8:52 PM
B
whats the best way to expose them? or how do i make
@sanity/image-urlwork in production?
Jan 7, 2022, 8:53 PM
This link says they need to be prefaced with
GATSBY_. You could try that, or you could try configuring them per these instructions .
Jan 7, 2022, 8:55 PM
B
i’ll try prefacing them … the second link is basically what i am doing now
Jan 7, 2022, 8:58 PM
B
user A
- ok that worked! but now, oddly, my local is broken with the /undefined/undefined
Jan 7, 2022, 9:18 PM
B
user A
- ok that worked! but now, oddly, my local is broken with the /undefined/undefined
Jan 7, 2022, 9:18 PM
When you added the preface, where did you update? There’ll be Gatsby Cloud settings, your code, and your .env.local file.
Jan 7, 2022, 9:33 PM
B
yep, all 3 of those
Jan 7, 2022, 9:34 PM
B
although my env is name
.env.developmentbut that seemed to work previously
Jan 7, 2022, 9:34 PM
B
although my env is name
.env.developmentbut that seemed to work previously
Jan 7, 2022, 9:34 PM
And the local
gatsby developprocess was killed and restarted since making the env changes?
Jan 7, 2022, 9:38 PM
B
ahh, nope
Jan 7, 2022, 9:41 PM
B
lol
Jan 7, 2022, 9:41 PM
B
yeah, i didn’t kill and restart develop
Jan 7, 2022, 9:42 PM
B
doing that now
Jan 7, 2022, 9:42 PM
B
same
Jan 7, 2022, 9:42 PM
B
yep, that resolved it… sorry to bother
Jan 7, 2022, 9:43 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.