Module not found: Error: Package path ./client is not exported from package
Asked Answered
R

3

6

I'm using nextjs and nextauth on nginx. I'm getting a build fail but I'm not sure how to fix this error.

2021-12-06T09:35:02.4779281Z https://nextjs.org/telemetry

2021-12-06T09:35:02.4779648Z

2021-12-06T09:35:02.7626345Z info - Checking validity of types...

2021-12-06T09:35:03.6479273Z warn - No ESLint configuration detected. Run next lint to begin setup

2021-12-06T09:35:03.6504824Z info - Creating an optimized production build...

2021-12-06T09:35:11.0167427Z Failed to compile.

2021-12-06T09:35:11.0168180Z

2021-12-06T09:35:11.0173424Z ModuleNotFoundError: Module not found: Error: Package path ./client is not exported from package /var/www/html/node_modules/next-auth (see exports field in /var/www/html/node_modules/next-auth/package.json)

2021-12-06T09:35:11.0177457Z

2021-12-06T09:35:11.0181521Z

2021-12-06T09:35:11.0184681Z > Build error occurred

2021-12-06T09:35:11.0202372Z Error: > Build failed because of webpack errors

2021-12-06T09:35:11.0203202Z at nextBuildSpan.traceAsyncFn (/var/www/html/node_modules/next/dist/build/index.js:397:19)

2021-12-06T09:35:11.0490267Z npm ERR! code ELIFECYCLE

2021-12-06T09:35:11.0502899Z npm ERR! errno 1

2021-12-06T09:35:11.0522169Z npm ERR! [email protected] build: `next build`

2021-12-06T09:35:11.0529617Z npm ERR! Exit status 1

2021-12-06T09:35:11.0538648Z npm ERR!

2021-12-06T09:35:11.0546568Z npm ERR! Failed at the [email protected] build script.

2021-12-06T09:35:11.0554061Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2021-12-06T09:35:11.0650303Z

2021-12-06T09:35:11.0658427Z npm ERR! A complete log of this run can be found in:

2021-12-06T09:35:11.0665933Z npm ERR! /home/ubuntu/.npm/_logs/2021-12-06T09_35_11_056Z-debug.log

2021-12-06T09:35:11.0875406Z ##[error]Bash exited with code '1'.

2021-12-06T09:35:11.0952428Z ##[section]Finishing: npm run build

Any help with what to do next? How do I fix this problem? I've been struggling with this error all morning today.

Rockbottom answered 6/12, 2021 at 9:43 Comment(2)
what is the version of next-auth you are using?Jim
latest. I have fixed it now. I had to downgrade to Nextjs v11.1.2 for it to workRockbottom
W
23

It seems next-auth/client was renamed to next-auth/react in v4:

https://github.com/nextauthjs/next-auth/releases/tag/v4.0.0-beta.1

Wellnigh answered 10/12, 2021 at 20:28 Comment(1)
true. I tried to rename to next-auth/react but I kept getting the same issues. I downgraded both my next-auth client and nextjs version to work.Rockbottom
S
5

Along with next-auth/react, Provide was renamed to SessionProvider. It should be as follows,

import { SessionProvider } from "next-auth/react"

export default function App({
  Component,
  pageProps: { session, ...pageProps },
}) {
  return (
    <SessionProvider session={session} refetchInterval={5 * 60}>
      <Component {...pageProps} />
    </SessionProvider>
  )
}

https://next-auth.js.org/getting-started/upgrade-v4

Stratus answered 20/1, 2022 at 9:43 Comment(1)
thanks. this was helpfulRockbottom
E
1

i think you should use "next-auth": "^3.29.0", this version of next-auth

Engineman answered 21/1, 2022 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.