process.env variables not available to process using DigitalOcean App Platform

I’ve specified environment variables in the app platform settings, made them available during build and run time, but the application doesn’t have access to them.

const API_URL = process.env.REACT_APP_API_URL;

The above is undefined, even though REACT_APP_API_URL is specified in the settings.

Am I missing something obvious?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Might not be the answer you want, but from sample examples I’ve seen, the env system doesn’t work.

See this example:

You have to add a .env and load from it. Which means you have to commit the .env to git. Committing to git means you can’t make your code public (if the env has sensitive details)

At least, that’s what I could find, unless there’s a way I don’t know of yet.

Same issue here, did you find a solution?

What does your run command look like? I was having the same issue until I changed my run command to this:

npm install -g serve
serve -s build

This makes sure node is in production mode.