Next.JS Background Tasks

I need help with something driving me crazy. This is a Next.Js problem not an uploadthing problem but I’m curious if anyone has ever faced this issue with Next.JS instrumentation.

I have a upload-thing.js file that handles file uploads. This file has import server-only at the top.

I have 3 long running tasks to perform after successful upload, I decided to introduce a Queue to my setup. I used BullMQ library. The queue and worker files are all part of the Next.JS application.


THE CHALLENGE: I need to start the Queue worker somewhere, somehow. This queue worker is a function I need to call once, preferably during boot.

THE PROBLEM: Server fails to start apparently because the “parent component” is a client component. This parent component happens to be the instrumentation.ts file that imports the file that contains the “import server-only” line.
Was this page helpful?