Cannot find NodeJS namespace after updating web pack

I have an Angular2 application that is built using WebPack. I upgraded WebPack from v1.8 to v2 and everything seems to be working fine. The only problem is that the old code has the following:

import Timer = NodeJS.Timer;
....
apptInterval: Timer;
....
this.apptInterval = setInterval(() => { ... }, 1000);

After the update, this gives me an error: TS2503: Cannot find namespace 'NodeJS'.

tsconfig.json is as follows:

{
"compilerOptions": {
   "target": "es5",
   "module": "commonjs",
   "moduleResolution": "node",
   "sourceMap": true,
   "emitDecoratorMetadata": true,
   "experimentalDecorators": true,
   "lib": ["es2015", "dom"],
   "noImplicitAny": true,
   "suppressImplicitAnyIndexErrors": true
   }
}

Docs for Angular / Webpack no longer have typings.json; however, even if I copy from the Webpack 1 directory, this does not help. Content - typings.json

{
"globalDependencies": {
  "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
  "node": "registry:dt/node"
  }
}

Interestingly, if I remove the links to NodeJS, everything will be fine. Like this:

apptInterval: any;
....
this.apptInterval = setInterval(() => { ... }, 1000);

F12, apptInterval ZoneTask. , , . , , typings install dt~node --global --save-dev ( typings.json, .

+6
2

tsconfig.app.json , node , :

  {
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es6",
    "baseUrl": "",
    "types": ["node"] --> ADD THIS
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}
+11

TypeScript @2.0 + @types:

npm install -D @types/node @types/jasmine

typings, typings/index.d.ts tsconfig.json:

{
  "include": [   // or "files"
    "typings/index.d.ts"
  ]
}
+2

Source: https://habr.com/ru/post/1015922/


All Articles