TypeError: path.resolve is not a function

Solution 1:

When you import factory.js, next is running entire file, it sees the "path" and it is throwing the error

path is used to get the directory of contract file, and fs is used to read the contract file. Then with solc compiler, you compile this code, you run this file with

  node fileName.js

based on instructions you defined with solc, this compilation with create a .json file which has "abi" property. So far we had nothing to do with next.js.

Then, refactor this to a separate file:

import abi from "directory/file.json"

const factory = new web3.eth.Contract(
    // pass the abi
    JSON.parse(abi),
    '0x2d54559dCe0DA6C92378A916e9eE0422CEFFCD80'
);

Now you have to import this into your next.js project.