I know you also just started using TypeScript recently and bumped into the following errors or might be similar kind of issues
Cannot find name ‘window’
Cannot find name ‘document’. Do you need to change your target library? Try changing the
lib
compiler option to include ‘dom’.
Cannot find name ‘console’. Do you need to change your target library? Try changing the
lib
compiler option to include ‘dom’.
It is because the TypeScript compiler doesn’t know anything about these global objects during compile time
Open tsconfig.json
in VSCode or in your favorite editor and add "DOM"
inside the lib
array
"lib": [ "ES6","DOM" ],
After the update, your tsconfig.json
should look something similar to this
{ "compilerOptions": { "lib": [ "ES6","DOM" ], "target": "ES6", "noImplicitAny": true, "outDir": "./dist", "rootDir": "./src", }, "exclude": [ "node_modules" ] }
And, once you save your changes the error should be fixed and you should be able to compile the TypeScript module.
If you are only targetting the NodeJS environment, install the @types/node
to get the node typings, You can achieve that by executing the below command
npm install @types/node --save-dev