NodeJS 未找到next-auth模块:无法解析“preact-render-to-string”getServerSession()

v1uwarro  于 2023-05-28  发布在  Node.js
关注(0)|答案(1)|浏览(115)

我正在将我的项目迁移到nextjs 13.4中的app/目录,当我尝试在服务器组件中使用getServerSession()访问会话时:

import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { getServerSession } from "next-auth";
import Link from "next/link";

export default async function Navbar() {
  const session = await getServerSession(authOptions);
  return (
    <div className="navbar  top-0">
      <div className="navbar-start">LOGO</div>
      <div className="navbar-center"></div>
      <div className="navbar-end">
        <ul className="menu menu-horizontal px-1">
          <li>
            <Link href={"/example"}>Avatar Studio</Link>
          </li>
          <li>
            <Link href={"/example"}>Calendar</Link>
          </li>
          <li>
            <Link href={"/example"}>Newsfeed</Link>
          </li>
          <li>
            <Link href={"/example"}>Profile</Link>
          </li>
        </ul>
      </div>
    </div>
  );
}

它抛出:

./node_modules/next-auth/core/pages/index.js:10:51
Module not found: Can't resolve 'preact-render-to-string'
slsn1g29

slsn1g291#

我通过将导入从next-auth更改为next-auth/next来解决它,直到我删除node_modules并重新安装,它仍然显示错误

相关问题