“next-auth Module not found: Can’t resolve ‘preact-render-to-string’ getServerSession()”

huangapple go评论68阅读模式
英文:

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 &quot;@/pages/api/auth/[...nextauth]&quot;;
import { getServerSession } from &quot;next-auth&quot;;
import Link from &quot;next/link&quot;;

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

it throws :

./node_modules/next-auth/core/pages/index.js:10:51
Module not found: Can&#39;t resolve &#39;preact-render-to-string&#39;

答案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

huangapple
  • 本文由 发表于 2023年5月22日 16:22:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304272.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定