6

I need to read some environmental variables on my node/react project.

After I installed dotenv

npm install dotenv --save

I import dotenv in my js file:

require('dotenv').config();

then I get an error for "fs"

Module not found: Error: Can't resolve 'fs' in '/Users/Na/projects/laa/node_modules/dotenv/lib'

So, is this because "file system" is not installed?

how to fix it?

cheers

manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216

1 Answers1

3

For the latest releases, you don't need the dotenv module any more. Environment variables are available with react-scripts@0.2.3 and higher. According to Create React App docs:

Environment Variables is available with react-scripts@0.2.3 and higher.

So the only thing you need to do is to create the .env file and put your variables in it with the prefix REACT_APP_{your variable name}, and then you can use any variable in your code using:

process.env.REACT_APP_{your variable name}