Solvedagenda typing issue


I am trying out agenda but facing with types issue hence, unable to proceed. Could be related to #1218, and #1265

The example usage of initializing agenda is const agenda = new Agenda({ db: { address: mongoConnectionString } });. However, the typing does not match what is in the docs.

const agenda = new Agenda({
  db: {
    address: 'mongodb://...',

export interface AgendaConfig {
name?: string;
processEvery?: string;
maxConcurrency?: number;
defaultConcurrency?: number;
lockLimit?: number;
defaultLockLimit?: number;
defaultLockLifetime?: number;
sort?: any;
mongo?: MongoDb;
db?: {
address: string;
collection: string;
options: MongoClientOptions;

The definition is as such, and since db.collection and db.options are not declared as optional (?), it will throw type error like such

Type '{ address: string; }' is missing the following properties from type '{ address: string; collection: string; options: MongoClientOptions; }': collection, options

The 2nd issue is the constructor error

TypeError: agenda_1.Agenda is not a constructor
    at Object.<anonymous> (Z:\scheduler-service\src\agenda.ts:4:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Module._compile (Z:\scheduler-service\node_modules\source-map-support\source-map-support.js:547:25)
    at Module.m._compile (C:\Users\Joseph\AppData\Local\Temp\ts-node-dev-hook-769800944806712.js:69:33)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at require.extensions.<computed> (C:\Users\Joseph\AppData\Local\Temp\ts-node-dev-hook-769800944806712.js:71:20)
    at Object.nodeDevHook [as .ts] (Z:\scheduler-service\node_modules\ts-node-dev\lib\hook.js:63:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
[ERROR] 01:02:28 TypeError: agenda_1.Agenda is not a constructor

Using agenda: 4.1.0 and typescript: 4.1.5

22 Answers

✔️Accepted Answer

I can confirm this works with node 14.16.0 and agenda 4.1.2. Faced this issue today after updating from 4.1.0 to 4.1.2.

import { Agenda } from 'agenda';

Other Answers:

As a temporary solution, this older version coupled with the deprecated typings seems to be working fine for me:

"agenda": "^3.1.0"
"@types/agenda": "^2.0.8"
const {Agenda} = require('agenda');

require agenda like this, and it works fine for me

I'll create a PR to show you what I mean. The problem with this approach would be furthermore that everyone who has changed their imports to { Agenda } will stop working again, and they would either need to require('agenda') again direclty:

I think the subsequent replies to this issue show that the longer this goes unpatched, the more painful it's going to be to go back to the old behaviour, because more people will have applied the fix that compensates for the behaviour change.

I don't have a particular preference and obviously the fix is easy, it's just unexpected when you have npm set to not take major version updates for the module. I have agenda in use across a bunch of projects and have pinned it back to 4.1.0 rather than make fixes to all those projects I think I might have to roll back.

I think it wouldn't be unreasonable to make a 4.1.3 that reverts to the old behaviour (even if it means losing typescript/import functionality), and immediately make a 5.0.0 that works the same way 4.1.2 does, but with the documentation fixed. That way users who blindly npm update won't find their code breaks, anyone who updated to 4.1.1/4.1.2 can update to 4.1.3 to fix the break; anyone who has applied the fix already will have the choice of rolling back their fix to use 4.1.3, or taking the major version update if they prefer the new interface.

Related Issues:

agenda typing issue
I can confirm this works with node 14.16.0 and agenda 4.1.2 Faced this issue today after updating fr...
agenda Agenda cannot initialize with MongoDB Unified Topology Design
Released in v3.0.0 🎉 If I set { useUnifiedTopology: true } in MongoDB connection options ...
n8n Reverse Proxy
Forget that found a helpful thread on server-sent events and nginx I added proxy_buffering off; prox...
bull Error: Could not remove job
@simpleshadow it has been a major pain point for my use case unfortunately along with this ...
bull Empty and clean jobs
a solution I used that doesnt involve adding another library is this: Hi I'm using bull in my Node.j...
bull Possible memory leak if too many process
It's a property not a method. node: v6.9.5 bull: ^3.0.0-alpha.1 It will throw this error (node:83132...
bull Share redis client across queues created by bull() calls?
Thanks @manast for the quick fix! That definitely helped! Locally it reduced my usage from 26 to 18 ...
bull Missing lock for job
We also have this issue but without any specific configuration (just host and port) no custom redis ...
horizon Timeout for long running task
I already found a solution to my problem Hi I have a task that will take a few minutes to complete ...
horizon Jobs get processed multiple times
After delving into Horizon Redis Queues Lua script and redis-cli I finally determined what my proble...
horizon can this be used to scale job processing to multiple servers?
So I was wondering this as well since we host our Laravel app on Heroku Heroku has the ability to ea...
horizon Multiple horizon instances on one server not working
I was facing a similar issue and what I did was to set up env variables to represent each worker I w...
huey Disable root logger in consumer
My workaround to avoid Huey's logging configuration: I'm converting an existing code base to use Hue...
airflow Negsignal.SIGKILL error on macOS
It's not completely related but I had a different error message and Google lead me here ...
airflow Migrate from 2.1.4 to 2.2.0
SQL we used from our deployment playbook to clean up these tables Obviously a disclaimer on running ...
airflow Airflow webserver not starting with SQLAlchemy==1.3.16
The problem seems to be SQLAlchemy version 1.3.16 which was released 8 hours ago i downgraded to 1.3...
airflow scheduler gets stuck without a trace
We just saw this on 2.0.1 when we added a largish number of new DAGs (We're adding around 6000 DAGs ...
airflow Add Production-ready docker compose for the production image
I have prepared some Dockerfiles with some common configuration Description In order to use the prod...
devextreme reactive How to change table border styles
Try this It worked for me. React Grid I checked the doc see how to style or create a custom theme fo...
devextreme reactive Fixed Header and Left / Right Column
Thank you for the clarification In your case you need to implement the VirtualTable plugin instead o...