I get this error when I try to open a page in the DApp I'm developing.
Error: Cannot find module 'fs-promise'
Require stack:
- /Users/Desktop/RecycleChain/node_modules/swarm-js/lib/api-node.js
- /Users/Desktop/RecycleChain/node_modules/web3-bzz/lib/index.js
- /Users/Desktop/RecycleChain/node_modules/web3/src/index.js
- /Users/Desktop/RecycleChain/.next/dist/ethereum/web3.js
- /Users/Desktop/RecycleChain/.next/dist/pages/registration.js
- /Users/Desktop/RecycleChain/node_modules/next/dist/server/require.js
- /Users/Desktop/RecycleChain/node_modules/next/dist/server/render.js
- /Users/Desktop/RecycleChain/node_modules/next/dist/server/index.js
- /UsersDesktop/RecycleChain/node_modules/next/dist/bin/next-dev
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/Users/Desktop/RecycleChain/node_modules/swarm-js/lib/api-node.js:1:11)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Module._compile (/Users/Desktop/RecycleChain/node_modules/source-map-support/source-map-support.js:492:25)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
This error only occurs when I use an import a smart contract instance from register.js (in ethereum folder) file to registration.js (in pages folder). I use this following import statement
import registerContract from '../ethereum/register'; // import SC instance
My File system looks like this
The content of register.js is this
import web3 from './web3';
import register from './build/Register.json';
const instance = new web3.eth.Contract(
register.abi,
'0x7126ec4f68added009015a1f5ac718c4896faa2e'
// Address of the regist.sol contract in ropsten network
);
export default instance;
The versions of fs-extra that I'm using is "fs-extra": "^9.0.1",.
Update: The error seems to disappear when I press enter between the lines of web3.js file but then it comes back again when I refresh the page.
this is web3.js:
import Web3 from 'web3';
//current provider is the provider injected by MetaMask
let web3;
//typeof is used to check if window is defined
if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
// We are in the browser and metamask is running.
//Connect metamask to the webapp
window.ethereum.enable();
web3 = new Web3(window.web3.currentProvider);
} else {
// We are on the server *OR* the user is not running metamask
const provider = new Web3.providers.HttpProvider( 'https://ropsten.infura.io/v3/a5dc022ed8df4754b509e1f289d10b05');
web3 = new Web3(provider);
}
export default web3;