0

I'm creating my first project in React/Next.js, using NextAuth.js for Auth-N. I'm loosely following along with the Getting Started guide on the NextAuth website, and I've created a [...nextauth].js page that contains the following code:

import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
export default NextAuth({
    providers: [
        GoogleProvider({
            clientId: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
        })
    ]
})

I'm using the Provider in a Header.js page that contains the following code:

...
import {useSession, signIn, signOut} from 'next-auth/react';

const Header = () => {
    const { data: session } = useSession()
    ...

    return (
        <header className="border-b border-gray-100 dark:border-gray-700">
            <div className="container mx-auto px-4 sm:px-6 py-4 flex justify-between items-center">
                <Logo />

                <div className={"flex items-center space-x-1 sm:space-x-2"}>
                    {!session ? (
                        <button type="button" onClick={() => signIn()} className="bg-blue-700 text-white px-4 py-2 rounded-md focus:outline-none focus:ring-4 focus:ring-blue-600 focus:ring-opacity-50 whitespace-nowrap">Sign in</button>
                    ) : (
                        <button type="button" onClick={() => signOut()} className="bg-blue-700 text-white px-4 py-2 rounded-md focus:outline-none focus:ring-4 focus:ring-blue-600 focus:ring-opacity-50 whitespace-nowrap">Sign out</button>
                    )}

                </div>
            </div>
        </header>
    )
};

export default Header;

However, when I spin up my site with 'npm run dev' and try to login, I get the following error:

Server Error
Error: Package subpath './providers/google' is not defined by "exports" in /Users/tysont/Workspace/brightnote/node_modules/next-auth/package.json

I'm using NextAuth 4.0.6 and I don't see a /google specific export mentioned anywhere in the NextAuth package.json locally or on GitHub. Should there be? What am I missing?

Tyson
  • 1,685
  • 15
  • 36

1 Answers1

1
  1. Make sure you have a compatible node version, I'm using 12.22.1.
  2. Check if the [...nextauth].js file name is written correctly.
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 31 '21 at 05:18
  • Thanks! I updated Node + NPM and everything works now. – Tyson Jan 02 '22 at 03:03