HomeTutorsContact

(Solved) Cannot find name '..'. Do you need to change your target library?

By Gulshan Saini
Published in Typescript
February 28, 2021
1 min read

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

How do we fix this?

If your target environment is a browser

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 your target environment is NodeJs

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

Tags

#typescript
Previous Article
3 Ways to fix Property '..' has no initializer and is not definitely assigned in the constructor.ts

Related Posts

Typescript
3 Ways to fix Property '..' has no initializer and is not definitely assigned in the constructor.ts
February 18, 2021
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

JavaScript
Angular
ReactJS
Typescript
Linux

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media