2016-05-30 204 views
1

嘗試構建包含angularfire2和firebase的項目時,出現打字稿錯誤。下面是包:Typescript找不到名稱'Firebase'

"angularfire2": "^2.0.0-beta.0", 
"firebase": "^2.4.2", 

,這裏是錯誤:

[10:58:34] Finished 'build.html_css' after 4.51 s 
[10:58:34] Starting 'build.js.dev'... 
c:/Dev/daybreak/node_modules/angularfire2/database/database.d.ts(8,29): error TS2304: Cannot find name 'Firebase'. 
c:/Dev/daybreak/node_modules/angularfire2/database/database.d.ts(9,31): error TS2304: Cannot find name 'Firebase'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth.d.ts(10,25): error TS2304: Cannot find name 'FirebaseCredentials'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth.d.ts(13,16): error TS2304: Cannot find name 'FirebaseAuthData'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth.d.ts(14,29): error TS2304: Cannot find name 'FirebaseCredentials'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth.d.ts(14,59): error TS2304: Cannot find name 'FirebaseAuthData'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth_backend.d.ts(4,44): error TS2304: Cannot find name 'FirebaseCredentials'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth_backend.d.ts(8,44): error TS2304: Cannot find name 'FirebaseAuthData'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth_backend.d.ts(9,25): error TS2304: Cannot find name 'FirebaseAuthData'. 
c:/Dev/daybreak/node_modules/angularfire2/providers/auth_backend.d.ts(11,38): error TS2304: Cannot find name 'FirebaseCredentials'. 

如果我打開node_modules database.d.ts,沒有對「火力地堡」這樣我就可以明白爲什麼進口這將失敗..它期望從哪裏獲得'Firebase'?

import { FirebaseListObservable } from '../utils/firebase_list_observable'; 
import { FirebaseObjectObservable } from '../utils/firebase_object_observable'; 
import { FirebaseListFactoryOpts } from '../utils/firebase_list_factory'; 
import { FirebaseObjectFactoryOpts } from '../utils/firebase_object_factory'; 
export declare class FirebaseDatabase { 
    private fbUrl; 
    constructor(fbUrl: string); 
    list(urlOrRef: string | Firebase, opts?: FirebaseListFactoryOpts): FirebaseListObservable<any[]>; 
    object(urlOrRef: string | Firebase, opts?: FirebaseObjectFactoryOpts): FirebaseObjectObservable<any>; 
} 

我不知道爲什麼它甚至檢查node_modules分型..它的一部分,我排除tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "declaration": false, 
    "removeComments": true, 
    "noLib": false, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "sourceMap": true, 
    "pretty": true, 
    "allowUnreachableCode": false, 
    "allowUnusedLabels": false, 
    "noImplicitAny": true, 
    "noImplicitReturns": true, 
    "noImplicitUseStrict": false, 
    "noFallthroughCasesInSwitch": true 
    }, 
    "exclude": [ 
    "node_modules", 
    "dist", 
    "typings/browser.d.ts", 
    "typings/browser", 
    "src" 
    ], 
    "compileOnSave": false 
} 

回答

-3

在它的核心,看來你沒有基地安裝Firebase類型。

任何Firebase API的根類都是Firebase類。所以最有可能的類型有:ref<Firebase>,就像「WOAH,這是'Firebase'的事情是什麼?」

結帳的install guide for AngularFire2

步驟3:

NPM安裝分型-g

分型安裝--save --ambient火力

+1

這並不能解決我的問題。 – Jim

1

添加到.TS此你的文件==>從'angularfire2'導入{AngularFire,FirebaseListObservable};