SimeonGriggs / sanity-plugin-vimeo

Creates a uneditable schema of documents populated by the Vimeo API
MIT License
5 stars 0 forks source link

Getting an error on my production build #2

Open simonlagneaux opened 3 years ago

simonlagneaux commented 3 years ago

Hi Simeon,

Thanks a lot for the plugin, it's been super handy for a site I'm building. It's working perfectly in my Dev environment, but I get a No Access Token found in .env.development error in the Sanity of my live Netlify build. I set up SANITY_STUDIO_VIMEO_ACCESS_TOKEN in the environment variables in Netlify but to no avail... Any thoughts what the problem could be?

Thanks!

SimeonGriggs commented 3 years ago

I only ever deploy to Sanity's hosted Studio, so not sure why Netlify is giving you drama.

From memory, environment variables are only available during build on Netlify, not during run time. On a project once I needed to write a .env file during the build process with the variables in it, so that they'd exist during run time. A quick search of Netlify's docs/forum might help.

simonlagneaux commented 3 years ago

Thanks! I looked around a bit but couldn't find a solution. I've harcoded it in VimeoComponent.js for now but that's less than ideal...

SimeonGriggs commented 3 years ago

Here's that example I've used before to create a .env file based on the build-time variables ... might work?

// ./create-env.js
const fs = require('fs')

fs.writeFileSync('./.env', `SANITY_STUDIO_VIMEO_ACCESS_TOKEN=${process.env.SANITY_STUDIO_VIMEO_ACCESS_TOKEN}\n`)

And in netlify.toml or your build command.

command = "node ./create-env.js && gatsby build"