[Solved] error TS2584: Cannot find name ‘console’. Do you need to change your target library? Try changing the ‘lib’ compiler option to include ‘dom’.

When running a ts file using ts-node in the terminal, I get an error.

bug to reproduce

Solution

// Install the runtime library of the TypeScript helper, including all TypeScript helper functions 
npm install -D tslib @types/node  

reason

console is not part of the EcmaScript standard. The console in the DOM is in the browser environment and belongs to the browser BOM API. The console in Node is an API in Node.js, which is defined by nodejs itself. Although the two have the same function, they are not the same thing.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *