Home > front end >  ReactJS frontend suddenly cannot resolve many of it's node modules
ReactJS frontend suddenly cannot resolve many of it's node modules

Time:01-18

I have been working on this application for several weeks on and off. I followed the same setup process as I have for all of my past projects, installed all modules using npm insall and initialised the package.json file. Everything was working perfectly until today when I tried running the app and got a long error indicating that app was failing to resolve the many of the files from its node modules folder. A similar message to the one below was generated for what appears to be many of my frontend node modules.

ERROR in ./node_modules/body-parser/lib/read.js 19:11-26
Module not found: Error: Can't resolve 'zlib' in 'C:\Users\user\Desktop\MyProjects\Personal projects\LessonGeekLogger\frontend\node_modules\body-parser\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "zlib": require.resolve("browserify-zlib") }'
        - install 'browserify-zlib'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "zlib": false }

The whole error consisted of several instances of the above message stacked on top of each other, each for a different frontend node module.

I checked for some of the files that the error indicated the app was not able to find but found them all in the exact directories described in the error. None of the mentioned files appear to have been deleted, modified, or moved making this even more puzzling. I also tried restarting VS Code, restarting my computer, and attempting to run the app from a new terminal, all to no avail. Beyond that I cannot think of anything I could have possibly done to cause something like this as on the outside none of the node modules appear to have been tampered with.

I am still fairly new to web development and the ReactJS framework so please excuse me if I've missed something obvious. I can provide any other relevant information if need be. Any assistance is greatly appreciated.

CodePudding user response:

Try to execute npm i in the terminal at the root of the project. If it doesn't help, then try deleting the folder node_modules and running the command npm i again

CodePudding user response:

I have figured out what was causing the error. Somewhere in my code the import import { response } from "express"; was automatically added. For some reason removing this seems to have fixed the error but I still do not know exactly why. Thank you to everyone who responded.

Link to other answer that had the same problem

  • Related