I have defined the following Angular2 component:
import {Component} from \'angular2/core\';
@Component({
selector: \'my-app\',
moduleId: module.id,
te
This is what I did that worked for me on Eclipse(Webclipse)/Windows.
Step 1:
Terminal
$ npm install @types/node --global --save
Step 2:
tsconfig.json
{
"compilerOptions": {
...,
"types": ["node"]
}
}
In addition, I had the following dependencies in my package.json, so I was using typescript 2.
"devDependencies": {
...
"typescript": "~2.0.10",
"@types/node": "^6.0.46",
...
},
It still did not work until i pasted this where i had module.id, on top of component. like this
declare var module: NodeModule;
interface NodeModule
{
id: string;
}@Component({module.id})
For those looking to do this with Typescript 2.x and @types, here's what you need to do:
npm install -D @types/node
types: ["node"]
under compilerOptions
in your tsconfig.json
file.I had a tough time finding the instructions for step 2.
Reference: Typescript issue 9184
Edit:
You could also do:
"typeRoots": [ "node_modules/@types" ]
under compilerOptions
in your tsconfig.json
file. This is instead of the types
property and has the benefit of automatically including any @types
you install with npm.For example:
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types"
]
}
}
[Second edit]
Apparently, with the latest typescript, you only need typeRoots
or types
if tsconfig.json
is not in the root of your project or your types are not stored in node_modules/@types
.
I hit this error when porting my @angular/angular2 Quickstart project into a new angular cli auto-generated project.
It seems that moduleId: module.id
isn't needed anymore.
This is the latest auto-generated component:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
Removing all occurances resolved my errors.
module.id
cannot find the name module.
Follow following steps to resolves this issue,
step 1: Install node module by using the below command
npm i @types/node --save
Step 2: modify the file tsconfig.app.json
under src/app
"types": [
"node"
]
For me, I had a tsconfig.app.json
that extended tsconfig.json
. So when I added "types": ["node"]
in tsconfig.json
, it was being overridden by the "types" property in tsconfig.app.json
. Adding "node" to the existing "types" property in tsconfig.app.config
fixed it.