Gatsby Cloud does not respect Preview Env variables

Joined
Apr 3, 2023
Messages
1
Reaction score
0
Country
India
I recently configured Gatsby Cloud for my Gatsby app, the github integration and previews seemed very useful. I was previously using circleci to do a production build and deploy to aws. I did not previously have a staging site where i deployed a development build.

I added my production env vars to the Build section of the environment variables settings. Then I added my development env vars to the Preview section. No matter what i configure in gatsby-config.js the build process that GC uses automatically defaults to production on my PR builds. There is no info on this in the docs unfortunately.

gatsby-config.js:

Code:
let activeEnv = process.env.GATSBY_IS_PREVIEW ? "development" : process.env.NODE_ENV || "development";

require("dotenv").config({
  path: `.env.${activeEnv}`,
});
console.log(`** Build Env: '${activeEnv}'`);
console.log("** BACKEND URL:", process.env.GRAPHQL_URL);
I see "development" logged for activeEnv during the PR Build process, which is what I expect. dotenv technically should be loading .env.development, but it doesnt end up with the development GRAPHQL_URL url. process.env.GRAPHQL_URL always logs out as the value in .env.production
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
11,629
Messages
27,572
Members
21,370
Latest member
BoltonPlumbing

Latest Threads

Top