2016-06-12 21 views
1

时,我有以下代码...找不到名称'module'。使用CommonJS的

@Component({ 
    module: module.id, 
    selector: 'hero', 
    templateUrl:'hero.component.html', 
    styleUrls: ['hero.component.css'], 
    directives: [HeroDetailComponent, MD_CARD_DIRECTIVES, MD_BUTTON_DIRECTIVES, MD_LIST_DIRECTIVES, MD_ICON_DIRECTIVES, MdToolbar, MD_INPUT_DIRECTIVES], 
    providers: [HeroService], 
    viewProviders: [MdIconRegistry] 
}) 
export class HeroComponent implements OnInit{ 
... 
} 

//tsconfig.js 
{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "rootDir": "src/ng2", 
    "moduleResolution": "node", 
    "sourceMap": false, 
    "inlineSources": true, 
    "inlineSourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "outDir": "public/ng2", 
    "noImplicitAny": false 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings/main", 
    "typings/main.d.ts" 
    ] 
} 

但是当我跑我得到...

的src/NG2 /组件/英雄/ hero.component.ts(15 ,13):错误TS2304:找不到名称'module'。

UPDATE

我试图根据this question

"globalDependencies": { 
    "node": "registry:dt/node#6.0.0+20160608110640" 
} 

,但我还是看到做的步骤...

对象字面可以只指定已知特性,和'模块'不存在类型

更新2更新引导文件后,看起来像这样...

import {bootstrap}  from '@angular/platform-browser-dynamic'; 
import {HeroComponent} from './components/hero/hero.component'; 
import { HTTP_PROVIDERS } from '@angular/http'; 
declare var module:any; 
bootstrap(HeroComponent, [ HTTP_PROVIDERS ]); 

我仍然看到

的src/NG2 /组件/英雄/ hero.component.ts (15,5):错误TS2345:类型'{module:string;选择器:字符串; template:string; styleUrls:string [];指令:(typeof He ...'不能分配给类型为'{selector?:string; inputs?:string [];输出?:string [];属性?:string [];参数的事件? '。 对象字面量只能指定已知属性,而'模块'不存在于类型'{selector ?: string; inputs ?: string []; outputs ?: string []; properties ?: string []; events ?:〜应变...“

这里是project

回答

1

更新

好吧,让我们把该行的打字稿定义文件,并添加一个引用使得f在引导程序文件中。在你的角启动脚本的顶部添加:

///<reference path="./path/to/custom.typings.d.ts"/>

然后,您需要创建在引用的路径的文件。在该文件中,添加一行:declare var module:any;

原来的答案

在你的角度启动脚本(调用角的bootstrap功能的脚本),近上面添加自举以下行:

declare var module:any;

我不知道为什么这个错误发生,因为像你我配置我的依赖建议。既然我知道它不会造成任何问题,我只是添加了行来让编译器停止抱怨

+0

试过了,但我似乎仍然有问题。有任何想法吗?查看更新 – Jackie

+0

结帐我编辑的答案。也许该行必须位于打印稿定义文件中。 – BeetleJuice

+0

我会尝试一下,我仍然可以使用systemJS作为我的transpiler吗? – Jackie