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

155
Visualizações
Cannot find name 'console'. What could be the reason for this?

The following snippet shows a typescript error at LINE 4:

import {Message} from './class/message';

function sendPayload(payload : Object) : any{
   let message = new Message(payload);
   console.log(message);   // LINE 4 
}

The error says:

[ts] Cannot find name 'console'.

What could be the reason for this? Why it cannot find the object console?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You will have to install the @types/node to get the node typings, You can achieve that by executing the below command,

npm install @types/node --save-dev

Hope this helps!

over 4 years ago · Santiago Trujillo Relatório

0

Add "dom" in your lib section in compilerOptions in tsconfig.json.

Example:

{
    "compilerOptions": {
        "rootDir": "src",
        "outDir": "bin",
        "module": "commonjs",
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es5",
        "lib": [
            "es6",
            "dom"    <------- Add this "dom" here
        ],
        "types": [
            "reflect-metadata"
        ],
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}
over 4 years ago · Santiago Trujillo Relatório

0

You can run npm install @types/node -D, and then you need to add types:[ 'node'] into your tsconfig.json also.

package.json

"devDependencies": {
    "@types/node": "^15.0.3"
}

tsconfig.json

{
  "compilerOptions": {
    "composite": true,
    "outDir": "./dist",
    "rootDir": ".",
    "declaration": true,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "target": "es6",
    "types": [
      "node"
    ],
    "lib": [
      "es6"
    ]
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}
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