diff --git a/src/db.ts b/src/db.ts index c2aa0c8..717b793 100644 --- a/src/db.ts +++ b/src/db.ts @@ -1,9 +1,13 @@ -import { MongoClient, type Collection, type Db } from 'mongodb'; +import mongodb, { type Collection, type Db } from 'mongodb'; import type { Config } from './config.js'; + +// mongodb v3.x is CommonJS; named ESM imports of its values aren't resolvable by +// Node's cjs-lexer, so pull runtime values off the default (module.exports). +const { MongoClient } = mongodb; import type { NotificationDoc, SendRecord, UserDoc } from './types.js'; export interface Repos { - client: MongoClient; + client: mongodb.MongoClient; db: Db; notifications: Collection; users: Collection; diff --git a/src/handlers.ts b/src/handlers.ts index ed8ff86..ee3c0ad 100644 --- a/src/handlers.ts +++ b/src/handlers.ts @@ -1,5 +1,7 @@ -import { ObjectId } from 'mongodb'; +import mongodb from 'mongodb'; import type { Config } from './config.js'; +// mongodb v3.x is CommonJS — take ObjectId off the default export (see db.ts). +const { ObjectId } = mongodb; import type { Repos } from './db.js'; import type { FcmClient } from './fcm.js'; import type { Mailer } from './mailer.js';