dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.
https://craco.js.org
Apache License 2.0
7.43k stars 499 forks source link

how to use REACT_APP_XXXX Env from create react app? #437

Closed tal-rofe closed 2 years ago

tal-rofe commented 2 years ago

with CRA I used an ENV : |

REACT_APP_BACKEND_URL="http://localhost:3000"

However when using CRACO this env variable seems to be undefined.

How can I use envs then?

dilanx commented 2 years ago

I just tested it and it looks like all REACT_APP_ env variables are still valid when using craco. How are you loading your env variables?

tal-rofe commented 2 years ago

@dilanx I just have .env.development file in root folder

dilanx commented 2 years ago

Sorry for the delay. I just tested it (on 7.0.0-alpha.7) and it worked as expected for me. Do you think you could share more info that I could potentially use to try and recreate your issue? A demo repo would work.

I created a .env.development file in the root folder of a project with craco installed and included a variable called REACT_APP_BACKEND_URL like you have. It was included in the project as expected when I started the dev server.

The issue could also have been caused by something else in your project rather than craco.