将 Prisma Adapter 与 Next Auth 集成 - 意外的令牌“导出”

发布于 2025-01-15 05:09:50 字数 2131 浏览 2 评论 0原文

我正在尝试使用 vercel 指南进行编码: https://vercel.com/guides/ nextjs-prisma-postgres。尝试将 adapter: PrismaAdapter(prisma) 添加到 [...nextauth].ts 时,我收到错误 Unexpected token 'export'。根据所附图像 - 它似乎源自 prisma_adapter 内的 node_modules 文件夹。

错误图像

[...nextauth].ts:

import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "../../../lib/prisma";

export default NextAuth({
  providers: [
    GithubProvider({
      clientId: process.env.GITHUB_ID,
      clientSecret: process.env.GITHUB_SECRET,
    }),
  ],
  adapter: PrismaAdapter(prisma),
  secret: process.env.SECRET,
});

package.json:

{
  "name": "hello-next",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@next-auth/prisma-adapter": "^1.0.2",
    "@prisma/client": "^3.11.0",
    "next": "12.0.10",
    "next-auth": "^4.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-markdown": "8.0.0"
  },
  "devDependencies": {
    "@types/node": "^17.0.14",
    "@types/react": "17.0.38",
    "prisma": "^3.11.0",
    "ts-node": "^10.7.0",
    "typescript": "^4.5.5"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "lib/prisma.tsx"]
}

I am trying to code-along with a vercel guide: https://vercel.com/guides/nextjs-prisma-postgres. I am getting an error Unexpected token 'export' when trying to add adapter: PrismaAdapter(prisma) to [...nextauth].ts. Per the attached image - it seems to originate in the node_modules folder inside prisma_adapter.

image of error

[...nextauth].ts:

import NextAuth from "next-auth";
import GithubProvider from "next-auth/providers/github";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "../../../lib/prisma";

export default NextAuth({
  providers: [
    GithubProvider({
      clientId: process.env.GITHUB_ID,
      clientSecret: process.env.GITHUB_SECRET,
    }),
  ],
  adapter: PrismaAdapter(prisma),
  secret: process.env.SECRET,
});

package.json:

{
  "name": "hello-next",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@next-auth/prisma-adapter": "^1.0.2",
    "@prisma/client": "^3.11.0",
    "next": "12.0.10",
    "next-auth": "^4.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-markdown": "8.0.0"
  },
  "devDependencies": {
    "@types/node": "^17.0.14",
    "@types/react": "17.0.38",
    "prisma": "^3.11.0",
    "ts-node": "^10.7.0",
    "typescript": "^4.5.5"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "lib/prisma.tsx"]
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度 2025-01-22 05:09:50

这是最新 @next-auth/prisma 中的一个错误 -adapter 版本,降级到 1.0.1 是目前唯一的解决方法。

this is a bug in the latest @next-auth/prisma-adapter version, downgrading to 1.0.1 is the only workaround for the moment.

淡忘如思 2025-01-22 05:09:50

此问题是由最近版本引起的下一个授权的。唯一的选择是按照 GitHub Issue< 中所述降级/a>.

其根本原因是由于将输出更改为 ESM 造成的。

This issue is caused by a recent release of next-auth. The only option is to downgrade as of now as mentioned in this GitHub Issue.

Root cause of this was caused by changing the outputs to ESM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文