Require('fs') is not working

Hello, i’ve mentioned that i can’t build my react js app because the webpack said:
Error: Can’t resolve ‘fs’
What am i missing?
here in docs:
they said, that i can require(‘fs’) and then use fs.readFileSync(). But something went wrong…

With React and Webpack you might need to use imports, but I might be wrong :slight_smile:
Could you try like this?

import fs from "fs"

Also check this topic about ESM and CJS

Unfortunately, no. Still the same result. Can’t resolve ‘fs’.

Oh, I found the reason! Thanks to that guy:

It’s needed to add fs to webpack externals in the similar way like os.

module.exports = {
    externals: {
        uxp: 'commonjs2 uxp',
        photoshop: 'commonjs2 photoshop',
        os: 'commonjs2 os',
        fs: 'commonjs2 fs'

hope this will help to somebody like me :slight_smile:


You should mark your answer as a solution if it solved your problem :wink:

thanks. saved me alot man

Happy to hear the quick tip helped :slightly_smiling_face:

1 Like