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

Naresh :

I have defined the following Angular2 component:

import {Component} from 'angular2/core';

@Component({
  selector: 'my-app',
  moduleId: module.id,
  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 module.id is referring to the CommonJS module 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": [
    "node_modules",
    "dist",
    "typings/browser.d.ts",
    "typings/browser",
    "src"
  ],
  "compileOnSave": false
}

How can I correct the TypeScript error?

yurzui :

Update

If you use Typescript 2^ just use the following command:

npm i @types/node --save-dev

(instead of --save-dev you can just use shortcut -D)

or install it globally:

npm i @types/node --global

You can also specify typeRoots or types in your tsconfig.json if you want but by default all visible “@types” packages are included in your compilation.

Old version

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-dev

Then your typings.json file will look like this:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Angular2 TypeScript - error TS2307: Cannot find module 'angular2/forms'

From Dev

angular with typescript error, cannot find name angular

From Dev

Cannot find external module 'angular2/angular2' - Angular2 w/ Typescript

From

Angular2 lazy loading module error 'cannot find module'

From Dev

Cannot find module in Angular2 typescript class

From Dev

angular2 quickstart cannot find name 'module'

From Dev

TypeScript cannot find module error

From Dev

Typescript cannot find name error

From Dev

Angular2, cannot find module 'app/models/user' error

From Javascript

TS2307: Cannot find module 'angular2/core' while importing Angular2 on TypeScript

From Dev

Cannot find namespace error for model in Angular2/TypeScript

From

Angular and Typescript: Can't find names - Error: cannot find name

From Dev

Typescript Compiler Error TS2307: Cannot find module "angular2/core" when loading from CDN without NPM

From Dev

TypeScript - module.exports throws error TS2591: Cannot find name 'module'

From Dev

Issue with typescript path resolution. (Error: Cannot find module '[module_name]')

From Dev

TypeScript error: Cannot find module 'moment'

From

Ignore "cannot find module" error on typescript

From Dev

Typescript resulting in cannot find module error

From Dev

Jenkins-Error: Cannot find module 'typescript'

From Dev

Cannot find module - typescript path alias error

From Dev

Typescript error - Cannot find name 'require'

From

typescript error - cannot find name 'process'

From Dev

Typescript Error: Cannot find name 'cordova'

From Dev

Angular2 cannot find a nested module

From

cannot find module 'angular2/core'

From Dev

Angular2 cannot find module '../webservices'

From Dev

Cannot find module 'angular2/angular2'

From Dev

Launching Typescript app in Visual Studio Code throws error "Cannot find module 'electron'"

From

Cannot find name 'jquery' in angular2

Related Related

  1. 1

    Angular2 TypeScript - error TS2307: Cannot find module 'angular2/forms'

  2. 2

    angular with typescript error, cannot find name angular

  3. 3

    Cannot find external module 'angular2/angular2' - Angular2 w/ Typescript

  4. 4

    Angular2 lazy loading module error 'cannot find module'

  5. 5

    Cannot find module in Angular2 typescript class

  6. 6

    angular2 quickstart cannot find name 'module'

  7. 7

    TypeScript cannot find module error

  8. 8

    Typescript cannot find name error

  9. 9

    Angular2, cannot find module 'app/models/user' error

  10. 10

    TS2307: Cannot find module 'angular2/core' while importing Angular2 on TypeScript

  11. 11

    Cannot find namespace error for model in Angular2/TypeScript

  12. 12

    Angular and Typescript: Can't find names - Error: cannot find name

  13. 13

    Typescript Compiler Error TS2307: Cannot find module "angular2/core" when loading from CDN without NPM

  14. 14

    TypeScript - module.exports throws error TS2591: Cannot find name 'module'

  15. 15

    Issue with typescript path resolution. (Error: Cannot find module '[module_name]')

  16. 16

    TypeScript error: Cannot find module 'moment'

  17. 17

    Ignore "cannot find module" error on typescript

  18. 18

    Typescript resulting in cannot find module error

  19. 19

    Jenkins-Error: Cannot find module 'typescript'

  20. 20

    Cannot find module - typescript path alias error

  21. 21

    Typescript error - Cannot find name 'require'

  22. 22

    typescript error - cannot find name 'process'

  23. 23

    Typescript Error: Cannot find name 'cordova'

  24. 24

    Angular2 cannot find a nested module

  25. 25

    cannot find module 'angular2/core'

  26. 26

    Angular2 cannot find module '../webservices'

  27. 27

    Cannot find module 'angular2/angular2'

  28. 28

    Launching Typescript app in Visual Studio Code throws error "Cannot find module 'electron'"

  29. 29

    Cannot find name 'jquery' in angular2

HotTag

Archive