相关疑难解决方法(0)

Angular2代码中的TypeScript错误:找不到名称'module'

我定义了以下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错误?

commonjs typescript angular

63
推荐指数
5
解决办法
5万
查看次数

标签 统计

angular ×1

commonjs ×1

typescript ×1