TS2584

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

Broken Code ❌

TypeScript code:

1
console.log('Hello, World!');

TypeScript compiler configuration (tsconfig.json):

1
2
3
4
5
{
"compilerOptions": {
"lib": ["es2017"]
}
}

Fixed Code ✔️

You have to add the following to your “tsconfig.json” file:

1
2
3
4
5
{
"compilerOptions": {
"lib": ["es2017", "dom"]
}
}

When you are working on an application which never runs in a browser but only in Node.js environments, then you could add @types/node to your devDependencies instead of adding "dom" to your "lib" section.