I'm working on a react and node project right now but I'm getting this:
Compiled with problems:X
ERROR in ./node_modules/ip/lib/ip.js 7:9-22
Module not found: Error: Can't resolve 'os' in '/home/jacob/Code/taekwondo-bulletin/node_modules/ip/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: { "os": require.resolve("os-browserify/browser") }'
- install 'os-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "os": false }
ERROR in ./node_modules/mongodb/lib/cmap/auth/gssapi.js 8:12-26
Module not found: Error: Can't resolve 'dns' in '/home/jacob/Code/taekwondo-bulletin/node_modules/mongodb/lib/cmap/auth'
ERROR in ./node_modules/mongodb/lib/cmap/auth/mongocr.js 8:15-32
Module not found: Error: Can't resolve 'crypto' in '/home/jacob/Code/taekwondo-bulletin/node_modules/mongodb/lib/cmap/auth'
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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
ERROR in ./node_modules/mongodb/lib/cmap/auth/mongodb_aws.js 8:15-32
Module not found: Error: Can't resolve 'crypto' in '/home/jacob/Code/taekwondo-bulletin/node_modules/mongodb/lib/cmap/auth'
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: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }
ERROR in ./node_modules/saslprep/lib/memory-code-points.js 3:11-24
Module not found: Error: Can't resolve 'fs' in '/home/jacob/Code/taekwondo-bulletin/node_modules/saslprep/lib'
ERROR in ./node_modules/socks/build/client/socksclient.js 42:12-26
Module not found: Error: Can't resolve 'net' in '/home/jacob/Code/taekwondo-bulletin/node_modules/socks/build/client'
ERROR in ./node_modules/socks/build/common/helpers.js 12:15-32
Module not found: Error: Can't resolve 'stream' in '/home/jacob/Code/taekwondo-bulletin/node_modules/socks/build/common'
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: { "stream": require.resolve("stream-browserify") }'
- install 'stream-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "stream": false }
I changed nothing with the project, came back the next day and this was happening. I've tried deleting and reinstalling node_modules and package-lock.json. I can't seem to find anything similar on the internet and have been stuck for days. Any help would be appreciated. There were more errors with mongodb but were seen as spam.
CodePudding user response:
That's because some packages are part of Node.js, but they don't exist in browsers.
You need to indicate them or set them to false.
Update your webpack configuration, setting the packages you are getting errors to false: os, dns, crypto, fs, net. Or better, add all these:
resolve: {
fallback: {
"child_process": false,
"process": false,
"fs": false,
"util": false,
"http": false,
"https": false,
"tls": false,
"net": false,
"crypto": false,
"path": false,
"os": false,
"stream": false,
"zlib": false
}
}