kinde-auth-nextjs icon indicating copy to clipboard operation
kinde-auth-nextjs copied to clipboard

Bug: Type error on build

Open jaemil opened this issue 1 year ago • 10 comments

Prerequisites

  • [x] I have searched the repository’s issues and Kinde community to ensure my issue isn’t a duplicate
  • [X] I have checked the latest version of the library to replicate my issue
  • [X] I have read the contributing guidelines
  • [X] I agree to the terms within the code of conduct

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

jaemil avatar Jan 29 '24 19:01 jaemil

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

peterphanouvong avatar Feb 01 '24 23:02 peterphanouvong

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

DanielRivers avatar Feb 23 '24 15:02 DanielRivers

@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!

Ronak-59 avatar Mar 02 '24 14:03 Ronak-59

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

DanielRivers avatar Mar 02 '24 17:03 DanielRivers

@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 avatar Mar 02 '24 20:03 Ronak-59

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

Ronak-59 avatar Mar 06 '24 18:03 Ronak-59

@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?

DanielRivers avatar Mar 06 '24 21:03 DanielRivers

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

Ronak-59 avatar Mar 07 '24 10:03 Ronak-59

Is this issue still open or someone solved it?

pilladipesh33 avatar Apr 05 '24 11:04 pilladipesh33

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!

Ronak-59 avatar May 24 '24 18:05 Ronak-59