我定义了以下Angular2组件:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
moduleId: module.id,
templateUrl: './app.component.html'
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我在第5行得到以下错误:
src/app/app.component.ts(5,13): error TS2304: Cannot find name 'module'.
Run Code Online (Sandbox Code Playgroud)
我相信module.id指的是CommonJS module变量(见这里).我在tsconfig.json中指定了CommonJS模块系统:
{
"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
}
Run Code Online (Sandbox Code Playgroud)
如何更正TypeScript错误?