My Next.js app worked fine yesterday but today it has an error like this:
error - ./node_modules/@urql/core/dist/ddbb86ae.mjs:1:0
Module not found: Can't resolve 'graphql'
Import trace for requested module:
./node_modules/@urql/core/dist/urql-core.mjs
./node_modules/urql/dist/urql.es.js
./pages/_app.js
https://nextjs.org/docs/messages/module-not-found
I have no idea what happened so I git reset --hard but the problem is still there.
Please help me fix it. I appreciate it.
_app.js:
import { StateContext } from "../lib/context";
import { Provider, createClient } from "urql";
const client = createClient({ url: "http://localhost:1337/graphql" });
function MyApp({ Component, pageProps }) {
return (
<StateContext>
<Provider value={client}>
<Nav />
<Component {...pageProps} />
</Provider>
</StateContext>
);
}
export default MyApp;
>Solution :
One possible solution to this issue is to check if the graphql package is installed in your project by running npm list graphql or yarn list graphql. If the package is not installed, you will have to install it.
Alternatively, you can try to update all the dependencies in your project by running npm update or yarn upgrade. This might fix any potential conflicts or issues with the dependencies in your project.
If the issue persists, you can try to clear the cache by running npm cache clean --force or yarn cache clean and then try rebuilding the project by running npm run build or yarn build. This might fix any potential issues with the build process.
It is also possible that the issue is caused by a conflict with the versions of the dependencies in your project. In this case, you can try to use the npm-check-updates or yarn upgrade-interactive commands to check for and update the outdated dependencies in your project.
Finally, if none of the above solutions work, you can try to create a new Next.js project and move your code to the new project. This might fix any potential issues with the project setup or configuration.