How to resolve missing 'fs', 'path', 'os' with react-script (no WebPack)?

40 views Asked by At

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.

0

There are 0 answers