Search code examples
aion

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


I was deploying my java contract to the Mastery network 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 at Contract.deploy (index.js?60f4:244) at _callee$ (Main.js?1523:40) at tryCatch (runtime.js?280d:65) at Generator.invoke [as _invoke] (runtime.js?280d:303) at Generator.prototype.<computed> [as next] (runtime.js?280d:117) at step (Main.js?1523:9) at eval (Main.js?1523:9) at new Promise (<anonymous>) at eval (Main.js?1523:9) at deploy (Main.js?1523:19)

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 here it is being used by the Aion node modules and not directly and therefore I can’t seem to find the way around it.


Solution

  • The issue got resolved here:

    https://github.com/aionnetwork/aion_web3/issues/78#issuecomment-513938605

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