我定义了以下 Angular2 组件:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
moduleId: module.id,
templateUrl: './app.component.html'
})
export class AppComponent {
}
当我尝试编译它时,我在第 5 行收到以下错误:
src/app/app.component.ts(5,13): error TS2304: Cannot find name 'module'.
我相信 module.id 指的是 CommonJSmodule
变量(参见here https://angular.io/docs/js/latest/api/core/ComponentMetadata-class.html)。我在 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
}
如何纠正 TypeScript 错误?