kinde-oss / kinde-auth-nextjs

Kinde NextJS SDK - authentication for server rendered apps
https://kinde.com/docs/developer-tools/nextjs-sdk/
MIT License
150 stars 20 forks source link

Bug: Type error on build #114

Closed jaemil closed 1 month ago

jaemil commented 8 months ago

Prerequisites

Describe the issue

Hi,

when i try to run pnpm build this type error occurs:

.next/types/app/api/auth/[kindeAuth]/route.ts:59:7:

Type error: Type '{ __tag__: "GET"; __return_type__: Promise<(req: any, res: any) => any>; }' does not satisfy the constraint '{ __tag__: "GET"; __return_type__: void | Response | Promise<void | Response>; }'.
  Types of property '__return_type__' are incompatible.
    Type 'Promise<(req: any, res: any) => any>' is not assignable to type 'void | Response | Promise<void | Response>'.
      Type 'Promise<(req: any, res: any) => any>' is not assignable to type 'Promise<void | Response>'.
        Type '(req: any, res: any) => any' is not assignable to type 'void | Response'.

  57 |         __return_type__: Response | void | never | Promise<Response | void | never>
  58 |       },
> 59 |       {
     |       ^
  60 |         __tag__: 'GET',
  61 |         __return_type__: ReturnType<MaybeField<TEntry, 'GET'>>
  62 |       },

Node version: 19.3.0

My package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "^3.501.0",
    "@aws-sdk/s3-presigned-post": "^3.501.0",
    "@aws-sdk/s3-request-presigner": "^3.501.0",
    "@kinde-oss/kinde-auth-nextjs": "^2.1.5",
    "@prisma/client": "^5.7.1",
    "@radix-ui/react-avatar": "^1.0.4",
    "@radix-ui/react-dialog": "^1.0.5",
    "@radix-ui/react-dropdown-menu": "^2.0.6",
    "@radix-ui/react-navigation-menu": "^1.1.4",
    "@radix-ui/react-scroll-area": "^1.0.5",
    "@radix-ui/react-separator": "^1.0.3",
    "@radix-ui/react-slot": "^1.0.2",
    "@radix-ui/react-tabs": "^1.0.4",
    "@tailwindcss/typography": "^0.5.10",
    "@tanstack/react-query": "^4.36.1",
    "@trpc/client": "^10.44.1",
    "@trpc/next": "^10.44.1",
    "@trpc/react-query": "^10.44.1",
    "@trpc/server": "^10.44.1",
    "@types/multer": "^1.4.11",
    "aws-sdk": "^2.1545.0",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.0.0",
    "filepond": "^4.30.6",
    "filepond-plugin-file-validate-type": "^1.2.8",
    "lucide-react": "^0.316.0",
    "multer": "1.4.5-lts.1",
    "next": "14.1.0",
    "next-connect": "^1.0.0",
    "next-themes": "^0.2.1",
    "react": "^18",
    "react-dom": "^18",
    "react-dropzone": "^14.2.3",
    "react-filepond": "^7.1.2",
    "react-hook-form": "^7.49.3",
    "tailwind-merge": "^2.1.0",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10.0.1",
    "eslint": "^8",
    "eslint-config-next": "14.0.4",
    "postcss": "^8",
    "prisma": "^5.7.1",
    "tailwindcss": "^3.3.0",
    "typescript": "^5"
  }
}

Any idea how to fix this error? Thanks

Library URL

https://github.com/kinde-oss/kinde-auth-react

Library version

2.1.5

Operating system(s)

Windows

Operating system version(s)

Windows 11

Further environment details

No response

Reproducible test case URL

No response

Additional information

No response

peterphanouvong commented 8 months ago

A quick fix could be to try export const GET = handleAuth() as any;

DanielRivers commented 7 months ago

@jaemil Are you able to check on the latest version of the SDK please? I don't see the issue now.

Ronak-59 commented 7 months ago

@DanielRivers this happened to us as well during production build on vercel.

Failed to compile.
src/app/api/auth/[kindeAuth]/route.ts
Type error: Route "src/app/api/auth/[kindeAuth]/route.ts" has an invalid export:
  "Promise<(req: any, res: any) => any>" is not a valid GET return type:
    Expected "void | Response | Promise<void | Response>", got "Promise<(req: any, res: any) => any>".
      Expected "Promise<void | Response>", got "Promise<(req: any, res: any) => any>".
        Expected "void | Response", got "(req: any, res: any) => any".
Error: Command "npm run build" exited with 1

Code:

import { handleAuth } from "@kinde-oss/kinde-auth-nextjs/server";
import { NextRequest } from "next/server";

export async function GET(request: NextRequest, { params }: any) {
  const endpoint = params.kindeAuth;
  return handleAuth(request, endpoint);
}

Version: 2.1.15 (latest) and also 2.0.10

@jaemil were you able to fix it or did any workaround help? Thanks!

DanielRivers commented 7 months ago

@Ronak-59 What version of the SDK are you using?

Ronak-59 commented 7 months ago

@Ronak-59 What version of the SDK are you using?

@DanielRivers We tried with version: 2.1.15 (latest) and also 2.0.10 of kinde-auth-nextjs and version 14.0.1 of nextjs

Also tried deployment on Netlify and it gave same error there too.

Build process on Vercel/Netlify gives error as I shared above and build process locally gives the error that @jaemil mentioned in the beginning.

Let me know if you need any more information :)

Ronak-59 commented 7 months ago

Hey @DanielRivers were you able to reproduce the error or figure out the cause/workaround?

DanielRivers commented 7 months ago

@Ronak-59 I have not succeeded yet. I will try more. If I can't are you willing to jump on a call to investigate?

Ronak-59 commented 7 months ago

@DanielRivers Thanks! Sure, happy to jump on a call.

pilladipesh33 commented 6 months ago

Is this issue still open or someone solved it?

Ronak-59 commented 4 months ago

Solution to this issue is buried here (Migration Guide section): https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk/#migration-guide

After following this migration guide, my issue got fixed.

If anyone still faces this issue, please try this. @pilladipesh33

@DanielRivers feel free to close this issue, thanks for the help!