I have set my netlify.toml file with [context.deploy-preview.environment] NODE_ENV = "development", but when I create a pull request, my NODE_ENV variable does not change , even if the context indicated during build is ❯ Context deploy-preview
I am using it in a function for a Gatsby site :
function dosmthng() {
if (process.env.NODE_ENV === "production") {
// do Something
} else { // do Something else }
}
And the result is always ‘// do something’ , even when I am in deploy-preview context…
Hi, @Matos28 welcome to the forums. Try these things:
Did you make sure that you have saved the changes to your netlify.toml file and committed them to your repository before creating the pull request?
Check that the environment variable NODE_ENV is set correctly; go to the “Build & deploy” section, and click on the "Environment" tab to see a list of environment variables. Make sure that NODE_ENV is listed and set to the correct value for the deploy-preview context.
I’m wondering is it possible to reassign default Netlify env var to my own env var that is used by my app?
So for instance, Netlify provides $URL env var - url of a deployed site. My app uses $AAA env var.
Is it possible somewhere in the admin dashboard to assign a custom env var this way?
As stated in this documentationURL is a read-only variable. If you require a different value than provided by Netlify, you’ll need to set another variable @matriar .
for anyone who’ll fall here
If you need Netlify env var to be fallthrough as different name:
updates to the build command npm run build → YOUR_VAR=$URL npm run build could make a trick.
It’s a bit ugly and poor scalable but for a MVP it is enough =)