模块未找到:错误:包路径./client未从包中导出。

5

我正在使用nginx上的nextjs和nextauth。构建失败了,但我不确定如何修复这个错误。

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! my-app@1.0.1 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 my-app@1.0.1 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

有什么建议?我该如何解决这个问题?我今天早上一直在为这个错误苦苦挣扎。


1
你正在使用的 next-auth 版本是什么? - whygee
最新的。我已经修复了它。我不得不降级到Nextjs v11.1.2才能使其正常工作。 - ninsau
3个回答

21

我尝试将名称更改为next-auth/react,但仍然遇到相同的问题。我降级了我的next-auth客户端和nextjs版本以使其工作。 - ninsau

5
除了 next-auth/react,Provide 已被重命名为 SessionProvider。应该如下所示:
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


谢谢。这很有帮助。 - ninsau

1

我认为您应该使用"next-auth": "^3.29.0",这个版本的next-auth。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接