最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Next.js 14 build error: Issues with setImmediate, MessageChannel, and invalid export types in API routes - Stack Ov

programmeradmin3浏览0评论

I'm building a web application with Next.js 14 and React, which includes an upload system that integrates with Replicate's APIs to allow users to create custom AI tools. However, I'm running into a few issues when I try to build the project using npm run build.

  1. Edge Runtime Warnings: During the build, I get warnings related to the use of setImmediate and MessageChannel in the scheduler and @clerk packages:

    pgsql
    

    A Node.js API is used (setImmediate at line: 11) which is not supported in the Edge Runtime. A Node.js API is used (MessageChannel at line: 14) which is not supported in the Edge Runtime.

    These warnings appear multiple times and seem to be tied to the integration of react-dom, @clerk/clerk-react, and related modules. The project seems to be attempting to use Node.js APIs that aren't compatible with the Edge Runtime in Next.js.

    • Documentation on Edge Runtime
  2. Type Error in API Route: I also encounter a compilation error in one of my API routes (app/api/admin/health/route.ts). Specifically, I see the following type error:

    python
    

    Type error: Route "app/api/admin/health/route.ts" has an invalid export: "Promise<NextResponse<unknown> | { userId: null; isAdmin: boolean; } | { userId: string; isAdmin: boolean; }>" is not a valid PUT return type: Expected "void | Response | Promise<void | Response>", got "Promise<NextResponse<unknown> | { userId: null; isAdmin: boolean; } | { userId: string; isAdmin: boolean; }>".

    It seems like the return type of my PUT request handler is incorrect, as it's returning a Promise<NextResponse> or a custom object, but Next.js expects it to be of type Promise<void | Response>.

    The specific part of the code causing the issue is:

    ts
    

    export async function PUT() { return { userId: null, isAdmin: false }; }

    I have checked the Next.js documentation on API route return types, but I'm still unsure how to resolve this.

Steps I've already tried:

  • Updating the dependencies (Next.js, React, Clerk).

  • Reviewing the Next.js Edge Runtime documentation.

  • Trying to adjust the return types in my API routes.

Has anyone else encountered these issues or have any suggestions for how to resolve them?

  1. Updating Dependencies: I have updated the project dependencies (Next.js, React, Clerk) to their latest versions.

  2. Adjusting API Route Return Type: I tried adjusting the return value of my PUT method to match the expected types (void | Response | Promise<void | Response>), but still encountered issues.

  3. Running the Build Command: I executed the npm run build command, which ultimately led to these warnings and errors, likely expecting to either build successfully or get a clearer error message for debugging.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论