node.jsnode-modulescreate-react-appwebpack-5

webpack < 5 does not include polyfills for node.js core modules


I m running a simple create-react-app project to test out JWT Authentication. I have made a node server for both the RESTFull API and another node server for create-react-app. The server for the API is runninng just fine. However, the server for create-react-app keeps crashing with a long list of errors as such:

Failed to compile.

Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/chokidar'
WARNING in ../../../node_modules/minimatch/minimatch.js 5:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/minimatch'

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

WARNING in ../../../node_modules/nodemon/lib/config/exec.js 20:14-63
Critical dependency: the request of a dependency is an expression

WARNING in ../../../node_modules/nodemon/lib/version.js 16:12-54
Critical dependency: the request of a dependency is an expression

ERROR in ../../../node_modules/chokidar/index.js 6:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/chokidar'

ERROR in ../../../node_modules/chokidar/index.js 7:16-31
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/chokidar'

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

ERROR in ../../../node_modules/chokidar/lib/constants.js 5:4-19
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/chokidar/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/chokidar/lib/constants.js 9:11-24
Module not found: Error: Can't resolve 'os' in '/Users/reevefernandes/node_modules/chokidar/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/chokidar/lib/fsevents-handler.js 3:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/chokidar/lib'

ERROR in ../../../node_modules/chokidar/lib/fsevents-handler.js 4:16-31
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/chokidar/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/chokidar/lib/nodefs-handler.js 3:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/chokidar/lib'

ERROR in ../../../node_modules/chokidar/lib/nodefs-handler.js 4:16-31
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/chokidar/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/glob-parent/index.js 4:23-52
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/glob-parent'

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

ERROR in ../../../node_modules/glob-parent/index.js 5:14-36
Module not found: Error: Can't resolve 'os' in '/Users/reevefernandes/node_modules/glob-parent'

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/is-binary-path/index.js 3:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/is-binary-path'

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

ERROR in ../../../node_modules/nodemon/lib/cli/parse.js 18:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/cli'

ERROR in ../../../node_modules/nodemon/lib/cli/parse.js 19:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/cli'

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

ERROR in ../../../node_modules/nodemon/lib/config/exec.js 1:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/config'

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

ERROR in ../../../node_modules/nodemon/lib/config/exec.js 2:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/config'

ERROR in ../../../node_modules/nodemon/lib/config/load.js 2:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/config'

ERROR in ../../../node_modules/nodemon/lib/config/load.js 3:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/config'

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

ERROR in ../../../node_modules/nodemon/lib/help/index.js 1:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/help'

ERROR in ../../../node_modules/nodemon/lib/help/index.js 2:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/help'

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

ERROR in ../../../node_modules/nodemon/lib/monitor/match.js 2:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

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

ERROR in ../../../node_modules/nodemon/lib/monitor/match.js 3:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

ERROR in ../../../node_modules/nodemon/lib/monitor/run.js 2:17-39
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

ERROR in ../../../node_modules/nodemon/lib/monitor/run.js 5:19-43
Module not found: Error: Can't resolve 'child_process' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

ERROR in ../../../node_modules/nodemon/lib/monitor/run.js 17:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

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

ERROR in ../../../node_modules/nodemon/lib/monitor/run.js 19:27-48
Module not found: Error: Can't resolve 'os' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

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/nodemon/lib/monitor/watch.js 8:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/monitor'

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

ERROR in ../../../node_modules/nodemon/lib/nodemon.js 2:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/nodemon/lib/rules/parse.js 3:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib/rules'

ERROR in ../../../node_modules/nodemon/lib/spawn.js 1:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/nodemon/lib/spawn.js 5:14-44
Module not found: Error: Can't resolve 'child_process' in '/Users/reevefernandes/node_modules/nodemon/lib'

ERROR in ../../../node_modules/nodemon/lib/utils/index.js 2:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/lib/utils'

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

ERROR in ../../../node_modules/nodemon/lib/version.js 3:9-22
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/nodemon/lib'

ERROR in ../../../node_modules/nodemon/lib/version.js 4:11-26
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/nodemon/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/nodemon/lib/version.js 5:11-40
Module not found: Error: Can't resolve 'child_process' in '/Users/reevefernandes/node_modules/nodemon/lib'

ERROR in ../../../node_modules/picomatch/lib/constants.js 3:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/picomatch/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/picomatch/lib/picomatch.js 3:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/picomatch/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/picomatch/lib/utils.js 3:13-28
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/picomatch/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: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }

ERROR in ../../../node_modules/pstree.remy/lib/index.js 1:13-42
Module not found: Error: Can't resolve 'child_process' in '/Users/reevefernandes/node_modules/pstree.remy/lib'

ERROR in ../../../node_modules/pstree.remy/lib/tree.js 1:14-44
Module not found: Error: Can't resolve 'child_process' in '/Users/reevefernandes/node_modules/pstree.remy/lib'

ERROR in ../../../node_modules/pstree.remy/lib/utils.js 1:14-44
Module not found: Error: Can't resolve 'child_process' in '/Users/reevefernandes/node_modules/pstree.remy/lib'

ERROR in ../../../node_modules/readdirp/index.js 3:11-24
Module not found: Error: Can't resolve 'fs' in '/Users/reevefernandes/node_modules/readdirp'

ERROR in ../../../node_modules/readdirp/index.js 6:4-21
Module not found: Error: Can't resolve 'stream' in '/Users/reevefernandes/node_modules/readdirp'

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 }

ERROR in ../../../node_modules/readdirp/index.js 7:16-31
Module not found: Error: Can't resolve 'path' in '/Users/reevefernandes/node_modules/readdirp'

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

ERROR in [eslint] EACCES: permission denied, mkdir '/Users/reevefernandes/Desktop/user-jwt/client/node_modules/.cache'

webpack compiled with 44 errors and 3 warnings
One of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it may break at any time.

babel-preset-react-app is part of the create-react-app project, which
is not maintianed anymore. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.

I went thorugh the following steps as shown in these forums:

Which means, I tried to downgrade the react version and reintsall dependencies and also tapped into the webpack.config.js file to add the required, the problem still seems to persist.

What must I do?

Thank you for your time!


Solution

  • I had a React.js and Firebase app and it was giving the same error. I solved my issue by removing require('dotenv').config();. New React.js versions automatically handles loading dotenv package into the files. So, if you have this line, it will give this polyfill error.

    This polyfill error can be seen not just with dotenv package but also with some other packages you have installed.