Could not find a declaration file for module 'bson'

Viewed 1656

I did a rm -rf node_modules && npm cache verify && npm install && npm run start and now my console is complaining about

node_modules/@types/mongodb/index.d.ts:46:78 - error TS7016: Could not find a declaration file for module 'bson'. '/Users/microurb/Projects/backend/node_modules/bson/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/bson if it exists or add a new declaration (.d.ts) file containing declare module 'bson';

46 import { Binary, Decimal128, Double, Int32, Long, ObjectId, Timestamp } from "bson";

I did not get this error at all before, how did this error come up just because of running the above?

I tried running npm i --save-dev @types/bson, but that did not solve that.

2 Answers

Fix this by installing bson as well

npm i --save-dev bson

It doesn't appear to be included in mongo deps for some reason

I was able to resolve this by just adding // @ts-ignore above:

import { Binary, Decimal128, Double, Int32, Long, ObjectId, Timestamp } from "bson";

inside the @types/mongodb package.

Related