Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

447
Vistas
Cannot find namespace NodeJS after webpack upgrade

I have Angular2 application that is built with 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 upgrade this gives me an error: TS2503: Cannot find namespace 'NodeJS'.

tsconfig.json looks like this:

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

The docs for Angular/Webpack no longer have typings.json; however, even if I copy from Webpack 1 directory, it doesn't help. The content is typings.json is

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

Interesting that if I remove references to NodeJS, everything works fine. Like this:

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

If I look under F12 debugger, the type of apptInterval is ZoneTask. I am sure there is a way to make it strong-typed, but it escapes me. The only suggestion I found was to run typings install dt~node --global --save-dev (which essentially updates typings.json, but doesn't help.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If you also have tsconfig.app.json in your working directory, try to add the attribute node to the types field. Like:

  {
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es6",
    "baseUrl": "",
    "types": ["node"] --> ADD THIS
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}
about 4 years ago · Santiago Trujillo Denunciar

0

For TypeScript@2.0+, use @types:

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

If you still want to hang on to typings, include typings/index.d.ts to your tsconfig.json:

{
  "include": [   // or "files"
    "typings/index.d.ts"
  ]
}
about 4 years ago · Santiago Trujillo Denunciar

0

Adding node to the types didn't work for me, "types": ["node"] but adding to the type roots did

{
  "compilerOptions":
  {
    ...
    "typeRoots": [
    "node_modules/@types"
    ]
  }
}
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda