Skip to content

[bun] [interop] Property 'formData' does not exist on type 'NextRequest'.ts, NextResponse.json invalid return type. #58360

@Thinkscape

Description

@Thinkscape

Link to the code that reproduces this issue

https://github.com/Thinkscape/form-data-does-not-exist-on-nextrequest

To Reproduce

Formdata type problem

  1. bun as runtime
  2. tsconfig compilerOptions.types = ["bun-types", "web"](example)
  3. api route handler
  4. req: NextRequest
  5. await req.formData()

Actual

❯ next build
   ▲ Next.js 14.0.3-canary.4

 ✓ Creating an optimized production build
 ✓ Compiled successfully
   Linting and checking validity of types  ..Failed to compile.

./app/form-data-missing/route.ts:4:26
Type error: Property 'formData' does not exist on type 'NextRequest'.

  2 |
  3 | export async function POST(req: NextRequest): Promise<any> {
> 4 |   const data = await req.formData();
    |                          ^
  5 |   return NextResponse.json({ data: [...data.entries()] });
  6 | }
  7 |

Expected

Build succeeds.

Invalid export

  1. bun as runtime
  2. tsconfig compilerOptions.types = ["bun-types", "web"] (example)
  3. api route handler
  4. return NextResponse.json({});

Actual

❯ next build
   ▲ Next.js 14.0.3-canary.4

 ✓ Creating an optimized production build
 ✓ Compiled successfully
   Linting and checking validity of types  ..Failed to compile.

app/invalid-return-type/route.ts
Type error: Route "app/invalid-return-type/route.ts" has an invalid export:
  "Promise<NextResponse<{ data: any[]; }>>" is not a valid POST return type:
    Expected "void | Response | Promise<void | Response>", got "Promise<NextResponse<{ data: any[]; }>>".
      Expected "Promise<void | Response>", got "Promise<NextResponse<{ data: any[]; }>>".
        Expected "void | Response", got "NextResponse<{ data: any[]; }>".

Expected

Build succeeds.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.6.0: Wed Oct  4 21:26:23 PDT 2023; root:xnu-8796.141.3.701.17~4/RELEASE_ARM64_T6000
Binaries:
  Node: 21.1.0
  npm: 10.2.0
  Yarn: 1.22.19
  pnpm: 8.3.1
Relevant Packages:
  next: 14.0.3-canary.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Package manager (npm, pnpm, Yarn), TypeScript (plugin, built-in types)

Additional context

Related to #55623 and oven-sh/bun#463

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptRelated to types with Next.js.bugIssue was opened via the bug report template.locked

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions