0

I have a .env file set up in my project ENV FILE

But when i console.log it i can only see the following object

{
  "NODE_ENV": "development",
  "PUBLIC_URL": ""
}

I tried using .env.local but the problem persists. I used create-react-app to bootstrap the react application

1
  • by default, you will not have access to env variables in client-side. read this Commented Jul 23, 2019 at 7:29

2 Answers 2

2

All your custom environment variables need to have the prefix REACT_APP_.

Like this:

REACT_APP_GOOGLE_MAP_KEY = asdfdtgsg34qrgaerg

More about environment variables with create-react-app

Sign up to request clarification or add additional context in comments.

Comments

0

You many be missing any one of this

  • The env file should be in your root (not in src)
  • the env variable name should be prefixed with REACT_APP_
  • You need to restart the server to reflect the changes.
  • After that you can access the variable like this process.env.REACT_APP_SOME_VARIABLE in your CRA app

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.