Module not found: Can't resolve './providers/MoralisDappProvider/MoralisDappProvider'

Hello, I get the following error on my Next.JS app

Module not found: Can’t resolve ‘./providers/MoralisDappProvider/MoralisDappProvider’

I am using the following dependencies:

I am stuck because I need MoralisDappProvider. How should I go about importing it?

Are you following a Moralis tutorial or project? Does this MoralisDappProvider folder (and MoralisDappProvider.js file) exist in your project structure?

You just need to check that path. E.g. if that’s your index.js file, there needs to be a providers folder alongside it (and then a MoralisDappProvider folder inside that one).

1 Like

@glad is right.
U need something like
import React, { useEffect, useState } from “react”;
import { useMoralis } from “react-moralis”;
import MoralisDappContext from “./context”;

function MoralisDappProvider({ children }) {
const { web3, Moralis, user } = useMoralis();
const [walletAddress, setWalletAddress] = useState();
const [chainId, setChainId] = useState();
useEffect(() => {
Moralis.onChainChanged(function (chain) {
setChainId(chain);
});

Moralis.onAccountChanged(function (address) {
setWalletAddress(address[0]);
});
}, []);

return (
<MoralisDappContext.Provider value={{ walletAddress, chainId }}>
{children}
</MoralisDappContext.Provider>
);
}

function useMoralisDapp() {
const context = React.useContext(MoralisDappContext);
if (context === undefined) {
throw new Error(“useMoralisDapp must be used within a MoralisDappProvider”);
}
return context;
}

export { MoralisDappProvider, useMoralisDapp };

in ./providers/MoralisDappProvider/MoralisDappProvider.js folder