React static Site env

Hello, cant read my env.

In my code i have that route
process.env.REACT_APP_API_BASE_ROUTE || “http://localhost:5000/api”;

In Render environment i save key REACT_APP_API_BASE_ROUTE with value.
Also update my build command like in render doc REACT_APP_API_BASE_ROUTE=$API_BASE_ROUTE npm run build
What did i wrong here ??
Tahnks for the answers.

If you use Vite check the documentation,env variables are set with different syntax than process.env.var

Hey, you can use it without process.env as well,unless it’s a commercial site… and i don’t think u need to use route var when with npm run build.

Just make sure all your routes with https://localhost:5000/api in code, are replaced with export const API_URL in a seperate file ; you will be able to import this in other files.

Example :
Replace →

With below:

Make sure you import/require the needed package to read env variables.

I.E. Node.js server script:
import * as dotenv from ‘dotenv’;

You may need to install it as well using npm

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.