1

I am trying to build my react and node.js web app but fail to build ever since fixing packages.

i get the following error


Module not found: Error: Can't resolve 'fs' in 'my-app/node_modules/dotenv/lib'


npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-app@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I have tried to clear the cache of node_modules, remove package-lock.json, re install with npm and re-build, but nothing works.

Does anyone know how to solve this please?

Joshua
  • 1,005
  • 1
  • 11
  • 16

2 Answers2

0

Node Core Modules like fs won't work in the browser because they require binaries that aren't present in the browser. It apparently has been stubbed out of create-react-app, as per this Github issue.

The web doesn't have a filesystem, so it makes sense it won't ever work. Unfortunately for you, it means you should find a workaround. What were you trying to achieve with fs ?

Orijhins
  • 142
  • 5
  • Thanks Orijhins, i never knew i was using 'fs', i never installed in and it isn't used within the project either. I added. "browser": { "fs": false, "path": false, "os": false } to the package.json But the issue still persists – Joshua Feb 18 '22 at 12:03
  • You may have used an older version of create-react-app, in which case I do believe they installed fs by default. You can then just uninstall it and rebuild to check if it solved your problem. – Orijhins Feb 18 '22 at 12:06
  • Since you say it's installed by default, do you know which version of react I will have to use ? – Joshua Feb 18 '22 at 12:11
  • You can read the doc here: https://create-react-app.dev/docs/getting-started. They recommend uninstalling create-react-app and using `npx create-react-app` instead – Orijhins Feb 18 '22 at 12:14
  • Ok ill check it out, thanks Orijhins – Joshua Feb 18 '22 at 12:16
0

This may be a short hand fix, but i removed the dotenv package and loaded my env variables into the Azure config variables.

Joshua
  • 1,005
  • 1
  • 11
  • 16