bullmq: Vercel add Job : TypeError: client.addJob is not a function
Thanks for developing this open source. I really enjoy it. I have encountered this problem when running on vercel serverless. The source code works perfectly fine on local.
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: client.addJob is not a function",
"reason": {
"errorType": "TypeError",
"errorMessage": "client.addJob is not a function",
"stack": [
"TypeError: client.addJob is not a function",
" at Function.addJob (/var/task/node_modules/bullmq/dist/classes/scripts.js:52:23)",
" at Job.addJob (/var/task/node_modules/bullmq/dist/classes/job.js:352:34)",
" at Function.create (/var/task/node_modules/bullmq/dist/classes/job.js:34:28)",
" at processTicksAndRejections (internal/process/task_queues.js:93:5)",
" at Queue.add (/var/task/node_modules/bullmq/dist/classes/queue.js:38:25)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: TypeError: client.addJob is not a function",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:327:22)",
" at process.emit (/var/task/___vc_sourcemap_support.js:587:21)",
" at processPromiseRejections (internal/process/promises.js:245:33)",
" at processTicksAndRejections (internal/process/task_queues.js:94:32)"
]
}
Example Code:
const connection = new IORedis(process.env.REDIS_URI);
const queue = new Queue('SENDEMAIL', { connection });
const job = await queue.add('SEND', { email });
I found a workaround for this while customizing the vercel.json file. Hope to be able to help anyone who is having this problem.
"functions": { "api/serverless.ts": { "includeFiles": "node_modules/bullmq/dist/commands/**", } },
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 34 (8 by maintainers)
Commits related to this issue
- fix: remove internal deps on barrel fixes #469 — committed to taskforcesh/bullmq by manast 3 years ago
- chore(release): 1.20.4 [skip ci] ## [1.20.4](https://github.com/taskforcesh/bullmq/compare/v1.20.3...v1.20.4) (2021-04-23) ### Bug Fixes * remove internal deps on barrel fixes [#469](https://github... — committed to taskforcesh/bullmq by semantic-release-bot 3 years ago
Upstash is going to be compatible very soon, when they support Redis Streams which is almost ready.
When a bundler runs (ie
webpack,rollup,esbuild), either directly or as Vercel must also be doing in the background, it cannot handle / resolve circular dependencies so it creates these orphaned stubs that register asundefinedat runtime.As an example of some on that list, these are the root cause: https://github.com/taskforcesh/bullmq/blob/master/src/classes/job.ts#L6 https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue-scheduler.ts#L3 https://github.com/taskforcesh/bullmq/blob/master/src/classes/repeat.ts#L3 https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue.ts#L5 https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L5
(In fact, looking at that list, the above should solve most of them).
If interested in making sure the package is able to be bundled, I have found it super useful to run
madgein the CI build loop to immediately detect problems. ieor
I found a workaround for this while customizing the vercel.json file. Hope to be able to help anyone who is having this problem.
@ctrlaltdylan any chances to report this issue to the Vercel team?
I had the same issue with esbuild. I solved it by declaring bullmq as external
esbuild --external:bullmqI do not know how vercel works but my feeling is that the deployment is missing the lua files: https://github.com/taskforcesh/bullmq/tree/master/src/commands which also is placed on the dist directory of the npm module at /bullmq/dist/commands If those lua scripts are in the correct place when any of BullMQ main classes are instantiated they will be loaded and you should not get any error.