0
我正在使用TypeScript,Angular 2和貓鼬。我使用NPM安裝貓鼬:DefinitelyTyped Typescript Definition不識別貓鼬的依賴關係
"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"
}
當然,貓鼬會將mongodb作爲依賴項安裝。我然後使用命令typipngs install dt~mongoose --global --save.
用來安裝貓鼬索引文件安裝貓鼬DefintielyTyped定義:
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/51c51f03549a63f8791865bf26480947e22f4902/mongoose/mongoose.d.ts
declare module "mongoose" {
import events = require('events');
import mongodb = require('mongodb');
import stream = require('stream');
import mongoose = require('mongoose');
等等,等等。當我運行tsc
,我得到以下錯誤:typings/globals/mongoose/index.d.ts(5,28): error TS2307: Cannot find module 'mongodb'
。它不適合npm install mongodb --save
,因爲它已經安裝了貓鼬。
解決此問題的正確方法是什麼?
謝謝!這工作。有沒有更好的方法,我可以寫我的typings.json,以更好地傳達一個事實,即mongodb是一種貓鼬的依賴性? –
我沒有意識到 –