Module not found: Error: Can't resolve 'util'

Viewed 69

My React app was working fine until today, when I run npm start the following error is displayed

Module not found: Error: Can't resolve 'util' in 'C:\Users\Lui\Desktop\React\BarPoint\node_modules\sass'

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: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }

I have tried to delete the node modules and did npm ibut still error is persisted,how do i resolve this?

1 Answers

I resolved this by adding the following code im my webpack.config file

fallback: { 
    util: require.resolve("util")
  },

then i did npm i util There was also an error about fs,,,After a lot of research i solved that by adding this code in the package.json in sass folder under node modules

"browser": {
    "fs": false
},

i also added the same code in my normal package.json

Related