Search code examples
node-modules

Can't resolve 'fs' in react-script


We tried updating react-scripts from 4.0.3 to 5.0.0 with react-data-export 0.6.0 and xlsx 0.17.2, and when we try to build it fails with the error Module not found: Error: Can't resolve 'fs' in react-data-export\node_modules\tempa-xlsx

What fix needs to be applied to maintain react-scripts version 5.0.0? I am using react-scripts and not webpack. Thanks!


Solution

  • Try adding this in node_modules\react-data-export\node_modules\tempa-xlsx\package.json

    "browser": {
      "fs": false,
      "path": false,
      "os": false
    }
    

    Worked with me.

    Edit: I just found out that I can't create Excel files anymore. After some research, it seems that 'fs' (which is used to interact with file system) was removed from react-scripts 5. So the only solution is to either use react-scripts 4.0.3, or use another Excel library.