Use my Nitro functions in a worker? #4086
Replies: 1 comment
-
|
I got this working today, I can't even believe it. Have been at this for months! The problemSidequest's Why import.meta.url doesn't work for path resolutionOur first instinct was to use Why we can't just re-export from nitro.mjsWe tried writing a thin shim that re-exported job classes from the compiled nitro.mjs chunk. Two problems:
The solution: esbuild standalone bundle + nitropack/runtime shimAfter each Nitro build, a compiled hook in nitro.config.ts runs esbuild on the original sidequest.jobs.js source file, producing a self-contained
The nitropack/runtime shim is needed because server utility files use useRuntimeConfig() to read config values — but the real nitropack/runtime immediately tries to load Some server files were using The jobsFilePath configIn the Sidequest init plugin, we pass The nitro.config.ts hook in full |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have Sidequest.js setup to run job tasks outside of Nitro (they run in a Node worker): sidequestjs/sidequest#125 (comment)
I want to call functions in this jobs, that are defined in my Nitro server/utils folder. The problem is, those files just don't exist at the paths Sidequest job thinks they do, because of the way Nitro just bundles everything when it gets deployed to the server.
Sidequest runs without a build step I think.
So when the job runs, it gives this error:
So whats involved with calling Nitro functions from outside Nitro?
A workaround I had thought of was to use a Nitro task, and call it via a CLI command or perhaps get
runTask()working in a job. But the limitation on tasks only being able to run one instance at a time prevents that from working. I'd need to run the same task concurrently, but with differentpayloads.Beta Was this translation helpful? Give feedback.
All reactions