Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 502
helloJSON Avatar asked Feb 08 '17 06:02

helloJSON


People also ask

How to fix cannot find name console error in Node JS?

To solve the "Cannot find name console" error, install the node types if running in Node.js by running npm i -D @types/node, or include dom in the lib array in your tsconfig.json file if your code is ran in the browser.

Why can’t I print anything on the console?

You get the following error when you try to print anything on the console. Below is the complete error message you get. C# is a case-sensitive language. That means, the C# compilers consider console and Console as different words. To fix this simple error message.

Do I need esnext for console log?

you separate values with comma and you don't need esnext for console.log to work. Share Improve this answer Follow answered Jul 8 '18 at 11:00 jcubicjcubic

How do I get console logwork?

There's a simpler, but hacky way to get console.logwork: instead of console.log(message)write eval('console').log(message). Share Improve this answer Follow answered Nov 24 '17 at 23:11


1 Answers

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!

like image 74
David R Avatar answered Oct 06 '22 00:10

David R