Skip to content

Commit

Permalink
Merge pull request #609 from Josh-Cena/docs-react
Browse files Browse the repository at this point in the history
docs: improve explanation about environment in React
  • Loading branch information
motdotla committed Jan 28, 2022
2 parents 55b649a + 1412693 commit d0fbd37
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -311,7 +311,11 @@ require('dotenv').config({ override: true })

### How come my environment variables are not showing up for React?

React has dotenv built in but with a quirk. Preface your environment variables with `REACT_APP_`. See [this stack overflow](https://stackoverflow.com/questions/42182577/is-it-possible-to-use-dotenv-in-a-react-project) for more details.
Your React code is run in Webpack, where the `fs` module or even the `process` global itself are not accessible out-of-the-box. `process.env` can only be injected through Webpack configuration.

If you are using [`react-scripts`](https://www.npmjs.com/package/react-scripts), which is distributed through [`create-react-app`](https://create-react-app.dev/), it has dotenv built in but with a quirk. Preface your environment variables with `REACT_APP_`. See [this stack overflow](https://stackoverflow.com/questions/42182577/is-it-possible-to-use-dotenv-in-a-react-project) for more details.

If you are using other frameworks (e.g. Next.js, Gatsby...), you need to consult their documentation for how to inject environment variables into the client.

### Can I customize/write plugins for dotenv?

Expand Down

0 comments on commit d0fbd37

Please sign in to comment.