Skip to content

Commit d0fbd37

Browse files
authored
Merge pull request #609 from Josh-Cena/docs-react
docs: improve explanation about environment in React
2 parents 55b649a + 1412693 commit d0fbd37

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,11 @@ require('dotenv').config({ override: true })
311311

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

314-
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.
314+
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.
315+
316+
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.
317+
318+
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.
315319

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

0 commit comments

Comments
 (0)