I have a problem with a React app (setup with CRA). I have setup Now with GitHub to deploy every push in branches. I have environmental variables on my app and I used Now secrets to hide them. I'm dealing with an issue though:
When Now automatically deploys from the latest push, I got an error in the console saying I have an invalid API Key. By checking the value from a log statement, I can see the API Key is undefined. Therefore the app doesn't work.
However, If I deploy my app manually (by running now), I don't get the error and my app is working fine.
Something that is weird too is that if I deploy the app manually, that is to say by running manually `now`, things work perfectly and the environmental variables are properly loaded. So I'm not sure if adding a Babel file would solve the problem as env variables are loaded when I deploy the app manually.
It's just when I push some code into my GitHub repo and that Now deploys from there that it seems env variables are not loaded.
I am using babel-plugin-transform-define like you shared @paulogdm, however, it doesn't get the process.env.* and I am left with hard-coding the values like (hoping at some point they'd pull as desired):
Admittedly at the top of next.env.js I am using require('dotenv').config() which I believe does not work per somewhere else I read, and I am now wondering if it is breaking things. I can try without it later if you'd think it would help.
@thomlom not sure if you and I were having the same issue with Environment Variables, but if you need Environment Variables as part of your build process you need to wrap it in a build object of now.json.