-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript LSP Cannot Resolve lib.dom.d.ts
Despite File Existing
#61157
Comments
I believe this line is wrong: lib: ["lib.dom.d.ts"] // should just be "lib.dom" The provided sample throws unrelated errors; please provide a true runnable sample if you need further help |
Thank you for your response. I updated
The full implementation of the language server can be found here: To reproduce the issue, you can clone my repository. The README contains instructions on how to run the extension and language server. Additionally, Let me know if you need any additional information to help diagnose the issue. |
We're not able to provide this level of support. If you have a single runnable standalone script that demonstrates a defect, we can look at that, but this API obviously works for everyone else so there's either something wrong with the way you're calling it, or something very specific about the scenario that needs to be distilled down into an actionable defect I recommend looking at how other people are using the API: https://github.com/search?q=getDefaultLibFileName&type=code |
Thank you for your response. After reviewing my implementation, I realized that I misunderstood the distinction between readFile and getScriptSnapshot in LanguageServiceHost. I had not properly implemented getScriptSnapshot, which led to the issue. Now that I understand the correct usage, I have fixed my implementation, and the problem is resolved. I appreciate your guidance. My apologies for taking up your time with my own oversight. Thank you for your time. |
🔎 Search Terms
typescript lsp lib.dom.d.ts not found
typescript cannot resolve lib.dom.d.ts
typescript language server missing global types
typescript global types missing
cannot find global type 'Array'
typescript lib.dom.d.ts fileExists but not found
typescript LSP missing standard library
🕗 Version & Regression Information
This issue occurs in all versions from 4.8.4 to the latest.
⏯ Playground Link
No response
💻 Code
The full code is available here:
server.ts in lunas-dev/lunas-vscode
🙁 Actual behavior
I am developing a VS Code extension that integrates TypeScript as part of my custom language.
To achieve this, the language server for my extension internally starts a TypeScript language server,
acting as a proxy to leverage TypeScript's features.
In this implementation, the TypeScript standard library (e.g.,
lib.dom.d.ts
) needs to be properly loaded,so I have added
lib.dom.d.ts
to thelib
setting. However, since the standard library is not being recognized,global objects like
console
andWindow
cannot be used within the language server.Upon investigation, TypeScript reports the error
lib.dom.d.ts cannot be found
even though the file physically exists.Error message from
console.log(tsService.getCompilerOptionsDiagnostics());
:However, immediately after this error message, a debug log confirms that fileExists() correctly detects the file:
This creates an inconsistency where TypeScript's diagnostics claim that the file does not exist, but the file system check confirms that it does.
Key inconsistencies:
lib.dom.d.ts
is missing.fileExists()
confirms that the file is actually present.lib.es2020.full.d.ts
) is only resolved aftergetCompilerOptionsDiagnostics()
runs.This suggests that TypeScript is either:
🙂 Expected behavior
TypeScript should correctly resolve
lib.dom.d.ts
when specified inlib: ["dom"]
orlib: ["lib.dom.d.ts"]
withingetCompilationSettings()
.Expected behavior:
No false missing file errors
lib.dom.d.ts
as missing iffileExists()
confirms its presence.Consistent file resolution
getCompilerOptionsDiagnostics()
to check forlib.dom.d.ts
before its resolution is complete.Correct caching behavior
Immediate correct default library resolution
getDefaultLibFileName()
should return the correct default library file before diagnostics are run, not after.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: