HiveBrain v1.2.0
Get Started
← Back to all entries
debugjavascriptCritical

Cannot find name 'console'. What could be the reason for this?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
reasoncouldnameconsolefindtheforthiscannotwhat

Problem

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?

Solution

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


If your tsconfig.json file has a types property, you should modify it or you'll have to explicitly import node.js types to use them:
{
"compilerOptions": {
...
"types": ["jsdom", ...],
...
},
...

Code Snippets

npm install @types/node --save-dev

Context

Stack Overflow Q#42105984, score: 354

Revisions (0)

No revisions yet.