Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

384
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

Nowadays you can use ECMAScript import. From

const someLib = require("someLib");

to

import * as someLib from 'someLib';
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda