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
.
Edge Runtime Warnings: During the build, I get warnings related to the use of
setImmediate
andMessageChannel
in thescheduler
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
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 typePromise<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?
Updating Dependencies: I have updated the project dependencies (Next.js, React, Clerk) to their latest versions.
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.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.