In a frontend project:
Module not found: Error: Can't resolve 'fs' in '/home/porton/Projects/passport_client_dfinity/node_modules/dotenv/lib'
...
Module not found: Error: Can't resolve 'path' in '/home/porton/Projects/passport_client_dfinity/node_modules/dotenv/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 }
...
Module not found: Error: Can't resolve 'os' in '/home/porton/Projects/passport_client_dfinity/node_modules/dotenv/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 }
The answer for WebPack is available here.
But I don't use WebPack, I use plain react-scripts:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"sources": "mops sources"
},
How to solve it in my case? Should I switch to WebPack?
Note that I did add
"browser": {
"fs": false,
"path": false,
"os": false
}
and this does not help.
package.json: For example, what should be the"start"script?react-scriptsis a wrapper over WebPack. But addingwebpack.config.jswithresolve.fallbackdoes not eliminate my error messages :-~webpack.config.jsdoes not load at all, because when I intentionally make a syntax error in this file,npm startandnpm run buildstill complaint aboutfs,os, andpath, not about a syntax error inwebpack.config.js.webpackdirectly, the (intentional) error inwebpack.config.jsdoes throw.