Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Can't resolve 'fs' in dotenv/lib

Tags:

node.js

fs

dotenv

All of a sudden, when creating a react production build, I get this error.

> [email protected] build
> react-scripts build

Creating an optimized production build...
Failed to compile.

Module not found: Error: Can't resolve 'fs' in '/workspace/safe-courier/client/node_modules/dotenv/lib'

I have searched on the web, found similar cases but different frameworks of which all were not of help in regards to this issue.

I have tried to uninstall dotenv and reinstall it again but i get the same error. I'm not sure what could be the problem understanding that fs module is part of nodejs and comes bundled with it

like image 595
Kally Avatar asked Mar 02 '26 01:03

Kally


1 Answers

To solve this:

  1. Create the .env file at the root level of you app
  2. Name your variables beginning with REACT_APP_ // that's the key !!
  3. Restart your server with npm start each time you change an env variable
  4. Use your variable with process.env.NAMEOFYOURVARIABLE

No need of dotenv for your React app.

like image 177
Stéphane Sulikowski Avatar answered Mar 04 '26 15:03

Stéphane Sulikowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!