AryanJ-NYC AryanJ-NYC - 1 year ago 159
TypeScript Question

DefinitelyTyped Typescript Definition doesn't recognize mongoose dependencies

I'm using TypeScript, Angular 2 and mongoose. I installed mongoose using NPM:

"dependencies": {
"@angular/common": "2.0.0-rc.6",
"@angular/compiler": "2.0.0-rc.6",
"@angular/core": "2.0.0-rc.6",
"@angular/forms": "2.0.0-rc.6",
"@angular/http": "2.0.0-rc.6",
"@angular/platform-browser": "2.0.0-rc.6",
"@angular/platform-browser-dynamic": "2.0.0-rc.6",
"@angular/router": "3.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.6",
"body-parser": "^1.15.2",
"bootstrap": "^3.3.6",
"core-js": "^2.4.1",
"express": "^4.13.4",
"jquery": "^3.1.0",
"mongoose": "^4.6.0",
"morgan": "^1.7.0",
"path": "^0.12.7",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.11",
"systemjs": "0.19.27",
"typescript": "^2.0.0",
"typings": "^1.3.2",
"zone.js": "^0.6.17"
"devDependencies": {
"jasmine-core": "^2.5.1",
"karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-firefox-launcher": "^1.0.0",
"karma-jasmine": "^1.0.2"

Of course, mongoose installs mongodb as a dependency. I then installed the mongoose DefintielyTyped definitions using command
typipngs install dt~mongoose --global --save.
That installs the mongoose index file:

// Generated by typings
// Source:
declare module "mongoose" {
import events = require('events');
import mongodb = require('mongodb');
import stream = require('stream');
import mongoose = require('mongoose');

etc., etc. When I run
, I get the following error:
typings/globals/mongoose/index.d.ts(5,28): error TS2307: Cannot find module 'mongodb'
. It doesn't feel right to
npm install mongodb --save
since it is already installed with mongoose.

What is the right way of fixing this?

Answer Source

It's not asking you to install the module, it's asking you to install the typings for mongodb. Typings by default do not install dependency typings. So you have to go through and install each dependencies manually.

Specifically for Mongoose, you are going to need the typings for mongodb, mpromise and mongoose-promise (I think that's all of them).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download