0

I'm using connect-mongo to store sessions in a typescript project directly with the mongodb driver, without using moongose. I'm initializing it with clientPromise as following:

const store = new MongoStore({
    clientPromise: getMongoPromise(),
    collection: config.get('sessionCollection'),
    touchAfter: 24 * 3600,
    ttl: Number(config.get('sessionDuration')) * 24 * 3600,
});

When I run my app in dev mode (with ts-node --transpile-only src/start.ts) everything works fine, but when I try to compile it using tsc it gives me this error:

$ tsc
node_modules/connect-mongo/src/types.d.ts(11,27): error TS2307: Cannot find module 'mongoose'.
error Command failed with exit code 2.

I'm not using moongose in my app so I don't want to install it just to silence this error. Is there another way to fix it?

Thanks!

aghidini
  • 2,855
  • 5
  • 29
  • 32

2 Answers2

0

mongoose must be installed in production dependencies npm i --save mongoose for typescript

And not in devDependencies npm i --save-dev mongoose.

Thomas Aumaitre
  • 651
  • 1
  • 7
  • 17
0

Actually I found it, I was missing the @types/connect-mongo dev package. I trusted VSCode that didn't warn me about missing types but I was wrong.

After installing it the compilation now runs fine:

yarn add -D @types/connect-mongo
aghidini
  • 2,855
  • 5
  • 29
  • 32