debugjavascriptCritical
Cannot find name 'console'. What could be the reason for this?
Viewed 0 times
reasoncouldnameconsolefindtheforthiscannotwhat
Problem
The following snippet shows a typescript error at LINE 4:
The error says:
What could be the reason for this? Why it cannot find the object
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
If your
@types/node to get the node typings. You can achieve that by executing the below command:npm install @types/node --save-devIf 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-devContext
Stack Overflow Q#42105984, score: 354
Revisions (0)
No revisions yet.