Naresh Naresh - 1 month ago 35x
TypeScript Question

TypeScript error in Angular2 code: Cannot find name 'module'

I have defined the following Angular2 component:

import {Component} from 'angular2/core';

selector: 'my-app',
templateUrl: './app.component.html'
export class AppComponent {

When I try to compile this, I get the following error on line 5:

src/app/app.component.ts(5,13): error TS2304: Cannot find name 'module'.

I believe is referring to the CommonJS
variable (see here). I have specified the CommonJS module system in tsconfig.json:

"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": [
"compileOnSave": false

How can I correct the TypeScript error?


You need to install node ambientDependencies. Typings.json

"ambientDependencies": {
    "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#138ad74b9e8e6c08af7633964962835add4c91e2",

Another way can use typings manager to install node definition file globally:

typings install dt~node --global --save

Then your typings.json file will look like this:

"globalDependencies": {
  "node": "registry:dt/node#6.0.0+20160608110640"