0

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.

8
  • Please, also explain how to use webpack in package.json: For example, what should be the "start" script? Commented Jan 16, 2024 at 3:41
  • I realized that react-scripts is a wrapper over WebPack. But adding webpack.config.js with resolve.fallback does not eliminate my error messages :-~ Commented Jan 16, 2024 at 4:00
  • It seems that webpack.config.js does not load at all, because when I intentionally make a syntax error in this file, npm start and npm run build still complaint about fs, os, and path, not about a syntax error in webpack.config.js. Commented Jan 16, 2024 at 4:01
  • When I run webpack directly, the (intentional) error in webpack.config.js does throw. Commented Jan 16, 2024 at 4:08
  • See stackoverflow.com/questions/70591567/… Commented Jan 16, 2024 at 4:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.