2017-05-05 35 views
0

對於我的應用程序,我想使用BSON。在C++服務器端,我使用了mongodb bsoncxx,所以我決定在瀏覽器中使用類似的庫。我發現它here。接下來,我找到了這個庫的聲明文件here何要使用第三方庫和聲明文件?

我下載了this code並把它放到我項目中的third_party/bson文件夾中。接下來我下載了一個declaration file,把它改名爲bson.d.ts並放入同樣的third_party/bson文件夾。

Main.ts我寫道:

import * as bson from './third_party/bson/bson'; 
let BSON = new bson.BSON(); 

在構建我有這樣的錯誤:

scripts/third_party/bson/bson.d.ts(7,1): error TS2688: Cannot find type definition file for 'node'. 
scripts/third_party/bson/bson.d.ts(27,100): error TS2304: Cannot find name 'Buffer'. 
scripts/third_party/bson/bson.d.ts(28,25): error TS2304: Cannot find name 'Buffer'. 
scripts/third_party/bson/bson.d.ts(40,25): error TS2304: Cannot find name 'Buffer'. 
scripts/third_party/bson/bson.d.ts(47,45): error TS2304: Cannot find name 'Buffer'. 
scripts/third_party/bson/bson.d.ts(51,19): error TS2304: Cannot find name 'Buffer'. 
scripts/third_party/bson/bson.d.ts(113,24): error TS2304: Cannot find name 'Buffer'. 

什麼是node,爲什麼我需要它,我怎麼能得到它,我應該在哪裏放它?

有沒有辦法一次獲得一個具有所有依賴關係的庫?

+0

您使用npm嗎? – Paarth

+0

您正在使用哪種版本的打字稿? – Paarth

+0

由於錯誤來自聲明文件,因此您可以使用[skipLibCheck](https://www.typescriptlang.org/docs/handbook/compiler-options.html) –

回答

1

嘗試安裝節點打字稿定義與

npm i @types/node --save-dev 

,並確保有這對你tsconfig.json文件。

"compilerOptions": { 
    [...] 
    "typeRoots": [ 
    "node_modules/@types" 
    ] 
} 
+0

'npm i'告訴我'ENOENT:沒有這樣的文件或目錄,打開'/ home/nc/package.json' – nikitablack

+1

這是因爲你還沒有初始化你的'package.json'。你必須在你的repo目錄下執行'npm init'。 – guduf

相關問題