Search code examples
npmnext.jsyarnpkgnext-auth

"next-auth/react" module not found when making custom email sign in page in next-auth


I'm making a NextJs application with next-auth for the authentication part. Email Sign In is successfully implemented using next-auth's own default pages.

But now I would like to have a custom sign in page. I followed the documentation for this, and added pages: { signIn: '/auth/signin' } in my [...nextauth].js file. Then, I added the given Email Sign In code in pages/auth/signin.js. But upon running yarn dev, I get this module not found error:

error - ./pages/api/auth/signin.js:1:0
Module not found: Package path ./react is not exported from package C:\...\node_modules\next-auth (see exports field in C:\...\node_modules\next-auth\package.json)
> 1 | import { getCsrfToken } from "next-auth/react"
  2 | 
  3 | export default function SignIn({ csrfToken }) {
  4 |   return (

Import trace for requested module:

https://nextjs.org/docs/messages/module-not-found

And I couldn't find any module named 'next-auth/react' in npm or yarn websites. Even in next-auth folder in node_modules, there is no 'react' named file...

How can I solve this? And am I doing anything wrong here?


Solution

  • I faced the same issue and realised the docs are for v4 where next-auth/react is used.

    You are probably on v3 where next-auth/client is used instead.

    To use the beta version, do:

    ➜ npm i next-auth@beta