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

前端 未结 11 1441
梦毁少年i
梦毁少年i 2020-11-30 03:13

I have defined the following Angular2 component:

import {Component} from \'angular2/core\';

@Component({
  selector: \'my-app\',
  moduleId: module.id,
  te         


        
11条回答
  •  醉话见心
    2020-11-30 03:36

    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"
    }
    

提交回复
热议问题