1

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"]
}

2 Answers2

0

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

mocherfaoui
  • 902
  • 1
  • 2
  • 11
0

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.

Nurul Sundarani
  • 5,550
  • 3
  • 23
  • 52