Mar*_* M. 8 javascript angular
我正在使用angular-cli来运行我的打字机动力angular2应用程序.我有这样的AppComponent
定义:
import { Component } from '@angular/core';
import { ServersListComponent } from './servers-list/servers-list.component';
@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives: []
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
angular-cli无法编译此文件,因为它会在行中提出此问题主题中提到的错误moduleId: module.id
.
我的tsconfig.json
文件定义如下:
{
"compileOnSave": false,
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"mapRoot": "",
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "../dist/",
"rootDir": ".",
"sourceMap": true,
"target": "es5",
"inlineSources": true
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
为此module.id
,您的项目必须是 commonjs 模块,即tsconfig.json 文件中module
设置的属性。commonjs
是不是这样:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs", // <-----
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
Run Code Online (Sandbox Code Playgroud)