Error while deploying Aion dApp through frontend : fs.readFileSync is not a function

I was deploying my contract through the frontend by using a MERN stack app and came across the following error while compiling:

Module not found: Error: Can't resolve 'fs' in '/home/parina/Documents/aion-counter/node_modules/aion-web3-eth/src'

To rectify this, I added

node: {
    fs: "empty"

to my webpack.config.js file.
After this, I was successfully able to compile my project and start the server but on opening the project in the browser, the contract was not deployed and I got the following error in the console:

TypeError: fs.readFileSync is not a function

After searching on various forums, I found out that fs is not supposed to be used on the frontend and I was suggested alternatives to it. But it appears that it is being used by the aion node modules and therefore I can’t seem to find the way around it.

The AION devs are probably faster in their responses on Github. This seems to be an aion-web3 problem/bug, so could create an issue there:

1 Like

This has been explained here:

Since fs cannot be used on the client-side, I deployed the contract in my MERN dApp on the server-side while doing the rest of the interactions on the client-side.

1 Like