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

388
Vistas
Angular Material (8) S2591: Cannot find name 'require'

I am trying to log date/time into the javascript console. The error message I am getting is as follows and was generated by the code below.

ETA: the code does work. The dates are going to the console. It is just the Error Message remains

Message:

ERROR in src/app/kdc/services/customers.api.service.ts(60,9): error TS2591: Cannot find name 'require'. Do you need to install type definitions for node? Try npm i @types/node and then add node to the types field in your tsconfig.

NOTE: I have already made changes to the tsconfig.json file and have also done npm i @types/node and npm i @types/node --save When running npm result was 3 high-security vulnerabilities (see below)

enter image description here

What can I do at this point?`

customer.api.service.ts

   getCustomers(): Observable<Customers[]> {
        return this.httpclient.get<Customers[]>(this._url)
        .pipe( catchError(this.handleError));
        
    } 

    handleError(error:HttpErrorResponse){
        let rval = Math.random().toString(36).substring(7).toUpperCase();
        require('log-timestamp');
        console.error('MSG NO :' + rval );
        console.error(error);
        return throwError(rval + " <-> " + error.name + " <-> " + error.statusText );
     } 

ETA I found the message here Cannot find name 'require' after upgrading to Angular4 and made the change to my tsconfig.app.json file - it may be overkill, but it worked ...

  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": [ "node" ],
    "typeRoots": [ "../node_modules/@types" ]
  },
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Make sure you put the type in your tsconfig.app.json not your tsconfig.json

  "compilerOptions": {
    "module": "esNext",
    "types": ["node"]
  },

Also make sure your systax in your component look like this

const someLib = require("someLib"); // make sure the name is match with your package name

Then stop angular cli then run again

over 4 years ago · Santiago Trujillo Denunciar

0

Nowadays you can use ECMAScript import. From

const someLib = require("someLib");

to

import * as someLib from 'someLib';
over 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