Some env vars loading in prod, some not - very strange

Hi all :slight_smile:

I’m having one very strange issue with my gatsby site.

Some of my environment variables are loading into production and some of are not. I have been through them with a fine tooth comb and also tested locally using a local yarn build > yarn serve as well as netlify dev - both work fine.

I’ve also copied .env vars from local to production several times to make sure I hadn’t just made a spelling mistake but still no luck.

I’m setting my environment variables using Netlify’s UI, not netlify.toml but I don’t see how this could cause the problem unless I’m missing something.

Is there a limit on the number of environment variables we can use on the free tier, is this a known issue someone has come across or can someone point down another debugging route please?

Thanks in advance :+1:

Hi there, glad you found us :wave: before we can help you, we need a little more information on the issues you are facing.

Please tell us:

Also, how many environment variables are you talking about here?

Thanks for picking this up, Perry.

Here’s the site -

There are only 8 environment variables.

What I have already tried:

  • Built the site locally with Gatsby build and running yarn serve, this worked puling through the environment variables from a local .env.production file
  • Built using netlify dev which I understand pulls the environment variables from Netlify (although could be wrong here!), this also worked fine locally
  • I’ve manually copied the env vars from my local env files to netlify’s UI several times to make sure I haven’t made any silly mistakes re spelling etc. The environment variables in question are client side so in Gatsby they need to be prefixed with GATSBY_ which they all are

I’m unsure what else to try form here, any advice would be massively appreciated!

Looking through the deploy log there is nothing there that seems to suggest an any errors

Hi, @tp-will. I’m not sure why they wouldn’t be there.

Are some of the environment variables “large”? Also, are they being used in Functions after the build is complete or only in the build environment during the build itself?

You might check to see if they are set but if something unexpected is happening to them (like \n being converted into a newline) by having the build environment log what it sees defined with the command env.

So, if your build command is:

gatsby build

Try changing it to this:

env ; gatsby build

This will log all environment variables defined the build environment (its bash shell) before the build command is run.

If you make this change, do you see all the environment variables correctly defined in the build logs?

1 Like