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
?
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.
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.
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
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With