I'm using angular-cli for running my typescript powered angular2 app. I have an AppComponent
defined like this:
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 {
}
angular-cli can't compile this file, because it complains with an error mentioned in topic of this question in the line moduleId: module.id
.
My tsconfig.json
file is defined as below:
{
"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"
]
}
To be able module.id
, your project must be a commonjs module, i.e. the module
attribute set to commonjs
in the tsconfig.json file. Is it the case:
{
"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"
]
}
A possible work-around could be to add a app.d.ts file like this
https://github.com/johnpapa/pbp-a2-ward/blob/010523471e70677ba2493eb615c8e6316e3d4ee8/app/app.d.ts
Since angular migrated to using webpack there is no longer a need to declare moduleId
as webpack plugins auto handle (add it) module.id
in the final bundle.
As of 13.03.2017 Angular has removed all references to moduleId
as it is now deprecated due to the inclusion of webpack.
We added a new SystemJS plugin (systemjs-angular-loader.js) to our recommended SystemJS configuration. This plugin dynamically converts "component-relative" paths in templateUrl and styleUrls to "absolute paths" for you.
We strongly encourage you to only write component-relative paths. That is the only form of URL discussed in these docs. You no longer need to write @Component({ moduleId: module.id }), nor should you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With