英文:
next-auth Module not found: Can't resolve 'preact-render-to-string' getServerSession()
问题
I'm migrating my project to the app/ directory in Next.js 13.4, and when I try to access the session using getServerSession()
in a server component:
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>
);
}
It throws an error:
./node_modules/next-auth/core/pages/index.js:10:51
Module not found: Can't resolve 'preact-render-to-string'
英文:
i'm migrating my project to app/ directory in nextjs 13.4 and when i try to access session using getServerSession()
in a server component :
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>
);
}
it throws :
./node_modules/next-auth/core/pages/index.js:10:51
Module not found: Can't resolve 'preact-render-to-string'
答案1
得分: 0
我通过将导入从 next-auth
更改为 next-auth/next
来解决了这个问题,直到我删除了 node_modules 并重新安装后,错误才消失。
英文:
i solved it by changing the import from next-auth
to next-auth/next
and it still showed the error until i deleted node_modules and reinstalled
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论