2016-05-04 268 views
2

目前我正在開發使用離子2角2打字稿版本的應用程序。我決定使用庫amqp-ts在我的應用程序中包含消息。我通過NPM安裝庫,如:錯誤TS2307:找不到模塊「藍鳥」

npm install amqp-ts 

一切正常,現在我已經得到的東西是這樣的:

/ app root directory 
+ node_modules 
    - amqp-ts 
     - lib 
      - amqp-ts.d.ts 
     - node_modules 
      - amqplib 
      - bluebird 
      - winston 

現在的問題出現了:我導入庫到我的組成部分,它是在the documentation的例子做...

import * as Amqp from "amqp-ts"; 

...當我嘗試部署應用程序,我得到了一個錯誤信息:

TypeScript error: C:/APPs/Test/Ionic2Angular2App/node_modules/amqp-ts/lib/amqp-ts.d.ts(2,26): Error TS2307: Cannot find module 'bluebird'. 
TypeScript error: C:/APPs/Test/Ionic2Angular2App/node_modules/amqp-ts/lib/amqp-ts.d.ts(50,12): Error TS2304: Cannot find name 'Buffer'. 

1.與所述第一錯誤消息

// exported Typescript type definition for AmqpSimple 
import * as Promise from "bluebird"; 
[...] 

2.與所述第二錯誤消息中的線的線(相同的文件:AMQP-ts.d.ts)

export class Message { 
    content: Buffer; 
    [...] 
} 

我希望你能幫助我。

+0

您是否安裝該庫的分型? – vintem

回答

5

除了常規軟件包安裝,您還需要安裝TypeScript類型。類型就像頭文件,它們包含所有的方法/類/接口定義。

要安裝類型您需要打字工具。最好的辦法是在全球範圍內安裝它,這樣你可以在每一個項目中使用它

npm install typings --global 

然後安裝新的分型裏面你的項目很簡單,圖書館第一個搜索:

typings search bluebird 

安裝:

typings install --save bluebird 

更多信息:https://github.com/typings/typings

+0

非常感謝,它解決了第一條錯誤信息。我還有第二個(「無法找到名稱緩衝區」),有什麼想法? – AntonioMendez

+0

相同的東西,你需要知道哪個庫提供緩衝區類型。緩衝區是一個內部NodeJS的東西,所以最好的辦法是安裝nodejs typings'類型安裝 - 節點節點' – PolishDeveloper

+1

無論如何,我看到這個ampq lib stil使用TSD(https://github.com/abreits/amqp- ts/blob/master/tsd.json),檢查從TSD文件的類型/遷移,它應該幫助你解決未來的問題(可能下一個錯誤將失蹤'winston'和'when'類型)。我不確定如何處理'Typings',因爲我也綁定到TSD,但是例如嘗試引用'node_modules/ampq-ts/libs/typings/tsd.d.ts'文件('') – PolishDeveloper

相關問題