2016-05-07 92 views
2

TypeScript和ng2 rc.1獲取錯誤:(20,15)TS2304:找不到名稱'module'。TypeScript和ng2 rc.1獲取錯誤:(20,15)TS2304:找不到名稱'module'

試圖在運行時

@Component({ 
    selector: 'Notes1', 
    moduleId: module.id, 
    directives: [ModalDialog, FORM_DIRECTIVES, DisplayError], 
    templateUrl: 'Notes1.html', 
    styleUrls: ['Notes1.css'] 
}) 

使用模塊的指令,因爲任何知道如何解決的TS錯誤..一切工作正常

問候

肖恩

回答

2

時該錯誤意味着TypeScript編譯器不知道module是什麼。快速修復:

declare var require: any; 

爲了使它更齊全,使用的定義從DefinitelyTyped/node

interface NodeRequireFunction { 
    (id: string): any; 
} 

interface NodeRequire extends NodeRequireFunction { 
    resolve(id:string): string; 
    cache: any; 
    extensions: any; 
    main: any; 
} 

declare var require: NodeRequire; 

interface NodeModule { 
    exports: any; 
    require: NodeRequireFunction; 
    id: string; 
    filename: string; 
    loaded: boolean; 
    parent: any; 
    children: any[]; 
} 

declare var module: NodeModule; 
+0

謝謝你,是的,我已經做了同樣的修復'''聲明VAR模塊:NodeModule;'''但我不知道(抱歉,我不是我的問題更清楚了)爲什麼它不是像平臺其餘部分一樣的@ angular2 import語句的一部分,關於 – born2net

+0

模塊對象在NodeJS中定義並在Node聲明文件中聲明。你要麼沒有這個聲明文件,要麼你沒有在tsconfig.json文件中正確引用它。 – moefinley

-1

我解決了這個問題是這樣的「的moduleId」模塊後,只需添加編號的方法:「 commonjs「,在我的tsconfig文件中,錯誤消失了!

希望這有助於 吉姆

相關問題