vscode icon indicating copy to clipboard operation
vscode copied to clipboard

typescript/lib/lib.d.ts not found in all jsconfig.json files without target

Open 06000208 opened this issue 2 years ago • 5 comments

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.74.0 and 1.75.0-insider
  • OS Version: Windows 11 x64 10.0.22621

Every project on my local system containing a jsconfig.json file without a target property has started reporting this error:

File 'd:/Program Files/Microsoft VS Code/resources/app/extensions/node_modules/typescript/lib/lib.d.ts' not found.
  The file is in the program because:
    Default library for target 'es3'

Some projects have it multiple times, others only once. I freshly installed insiders to test, with no settings or extensions, and it occurs there too.

It doesn't occur if you have target as one of your compiler options, but this wasn't necessary before. My code isn't compiled with typescript; I use jsconfig so vscode recognizes my files as being part of the same project, and other similar reasons.

Working as normal when target is specified: 2022-12-08-Code_-_Insiders-1670492789

Examples of the issue: 2022-12-08-Code_-_Insiders-1670491612 2022-12-08-Code-1670491586

Steps to Reproduce:

  1. Open an empty folder in vscode
  2. Create an empty index.js file
  3. Create a jsconfig.json with valid properties without specifying a compiler options target.

06000208 avatar Dec 08 '22 09:12 06000208

Same question, when creating vite project:

pnpm create vite
# config...

cd my-proj
pnpm i
pnpm dev

9 Errors in tsconfig.node.json:

[{
	"resource": "/d:/WorkSpace/sanic-vue-exam/vue-simple-exam/tsconfig.node.json",
	"owner": "typescript",
	"severity": 8,
	"message": "File 'd:/Pro/Microsoft VS Code/resources/app/extensions/node_modules/typescript/lib/lib.d.ts' not found.\n  The file is in the program because:\n    Default library for target 'es3'",
	"source": "ts",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 2
}]

Sun-ZhenXing avatar Dec 08 '22 11:12 Sun-ZhenXing

I also had this error in tsconfig.node.json. I restarted TS Server in VSCode and then it fixed.

cmd + shift + p

image

Medkhat avatar Dec 08 '22 13:12 Medkhat

I also had this error in tsconfig.node.json. I restarted TS Server in VSCode and then it fixed.

cmd + shift + p

image

I tried this, but it didn't work for me. I thought I was the only one with this issue after updating VS Code.

EDIT: So, what I did to fix this issue was copy a lib.d.ts file from a recent project I worked on to the lib directory. The error was no longer present after saving via the jsconfig.json file.

Before: image

After: image

EDIT #2: I downloaded an older version of VS Code for macOS (1.73.1) and copied the file from Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.d.ts. The reason was because the current version (1.74.0) did not have the file in the lib directory. I observed some of the lib.d.ts files on my Mac were different. The file in the lib directory looks like this:

image

Here is the code:

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */



/// <reference no-default-lib="true"/>


/// <reference lib="es5" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />

starlightroad avatar Dec 08 '22 16:12 starlightroad

Igual me esta pasando, de la nada salio el problema.

dcarias0388 avatar Dec 08 '22 16:12 dcarias0388

Same issue on Mac Ventura

sagargulati avatar Dec 08 '22 18:12 sagargulati

I am also having this issue on Mac Ventura. Restarting the Typescript server or even restarting VS Code only solves the problem for a few minutes, then it resurfaces.

kevinswarner avatar Dec 08 '22 18:12 kevinswarner

Having the same issue. Tried the two solutions above and still having the same issue.

ashmchang avatar Dec 08 '22 18:12 ashmchang

Having the same issue. Tried the two solutions above and still having the same issue.

Try downloading an older version of VS Code and copy the file from there to the location of the error you are seeing. Then, try saving via the jsonfig.json file.

starlightroad avatar Dec 08 '22 18:12 starlightroad

I am also having this issue on Mac Ventura. Restarting the Typescript server or even restarting VS Code only solves the problem for a few minutes, then it resurfaces.

Try to download an older version of VS Code for Mac, say 1.73.1, and copy the lib.d.ts to the directory path Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib. The file is located in the same path the error shows. I restarted VS Code to see if the error would resurface. But, it has not. Hopefully, that fixes it.

starlightroad avatar Dec 08 '22 18:12 starlightroad

Here is what worked for me!

Close the VS Code.

yarn global add next@latest yarn global add typescript@latest

Open your project rm -rf node_modules package-lock.json

Re-open your project!

Also, check your VS Code extension, Install the official Javascript & Typescript extension by Microsoft.

I hope this helps!

sagargulati avatar Dec 08 '22 19:12 sagargulati

Thanks @sagargulati I just install the extension and with that works

luispied avatar Dec 09 '22 13:12 luispied

Thank you @sagargulati. Installing the extension and restarting VSCode worked for me.

IvanovRoman avatar Dec 10 '22 11:12 IvanovRoman

It worked for me too :)

Urszula-Molska avatar Dec 10 '22 12:12 Urszula-Molska

Added "target": "esnext" and now it just works.

# tsconfig.node.js
{
  "compilerOptions": {
    "target": "esnext",
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true
  },
  "include": [
    "vite.config.ts"
  ]
}

gnuion avatar Dec 10 '22 13:12 gnuion

Thanks @sagargulati. install the extension worked for me

soheilous avatar Dec 11 '22 08:12 soheilous

Same in a create-vue app, same cause.

segevfiner avatar Dec 11 '22 14:12 segevfiner

I tried all the solutions suggested above but none of it worked. I am using React + Vite + Typescript.

Screenshot 2022-12-11 at 22 01 58

The thing that solved my problem was to install @emotion/react @emotion/styled. Because I am using Material UI with Styled components and they are saying that there is some kind of problem with Styled Components and that they advise people to use Emotion.

Screenshot 2022-12-11 at 22 19 12

HugoRamonPereira avatar Dec 12 '22 01:12 HugoRamonPereira

I just did

cmd + shift + p

and used the Workspace version instead of VS Code. It worked.

image

abubakarkhawaja avatar Dec 12 '22 05:12 abubakarkhawaja

Added "target": "esnext" and now it just works.

# tsconfig.node.js
{
  "compilerOptions": {
    "target": "esnext",
    "composite": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "allowSyntheticDefaultImports": true
  },
  "include": [
    "vite.config.ts"
  ]
}

Thanks man. It's worked for me.

Wellitonzs avatar Dec 12 '22 11:12 Wellitonzs

Added "target": "ESNext" and now it just works. { "compilerOptions": { "target": "ESNext", "composite": true, "module": "ESNext", "moduleResolution": "Node", "allowSyntheticDefaultImports": true }, "include": ["vite.config.ts"] }

hbnxgdh avatar Dec 13 '22 05:12 hbnxgdh

@hbnxgdh is a Gigachad

reservecrate avatar Dec 13 '22 09:12 reservecrate

I also had this error in tsconfig.node.json. I restarted TS Server in VSCode and then it fixed.

cmd + shift + p

image

This worked for me. Thanks

CodeThag avatar Dec 13 '22 14:12 CodeThag

add "target": "esVersion" with esVersion like es6, es2017, es2020, ... in compilerOptions this worked for me :)

ndhieu2701 avatar Dec 13 '22 17:12 ndhieu2701

Seems fixed on Update 1.74.1. Thanks!

daramir avatar Dec 14 '22 23:12 daramir

@daramir i confirm, the latest update works

andrei22b avatar Dec 15 '22 10:12 andrei22b

Problem fixed on [email protected]

Asitha-Karnatakam avatar Dec 16 '22 11:12 Asitha-Karnatakam

I also solved this problem in 1.74.1.

iksflow avatar Dec 20 '22 06:12 iksflow