Adamgreg
Adamgreg16mo ago

`deno check` error: Cannot find name 'Deno'`

In my project, deno check has started producing the error TS2304 [ERROR]: Cannot find name 'Deno' . I've found a lot of reports about this error coming from the VS Code extension, but in my case it's coming from Deno itself, and the VS Code extension does NOT show this problem. I'm quite confused! Can anybody suggest a solution please?
7 Replies
Adamgreg
AdamgregOP16mo ago
In case it helps anyone else: I resolved the problem by adding /// <reference lib="deno.ns" /> to the top of the module that used the Deno object. I still don't know why that became necessary (after updating a dependency?), and why is it not necessary in every module that uses Deno
bartlomieju
bartlomieju16mo ago
Probably because a dependency uses a directive like this an overrides the default library. Vscode should provide you with a hint to add this exact reference
Adamgreg
AdamgregOP16mo ago
Ah, thanks. I didn't see a hint from VS Code. Since the Typescript compiler is bundled inside Deno itself in this case, would it be possible to make a change in Deno so that this is unnecessary? I assume there's no scenario where Deno is unavailable?
bartlomieju
bartlomieju16mo ago
I'm not sure, kinda makes sense. @dsherret thoughts on this?
Fifth-Normal-Form
It's been my experience that once you add a /// <reference to a file, it's represented in all other files. At least in main.ts, in my case. I write all front end code in TS and bundle with esbuild. In main.ts, I add /// <reference lib="dom" />, and never need to add it in other files. VSCode on Windows.
dsherret
dsherret16mo ago
GitHub
Prevent no-default-lib removing Deno global? · Issue #20420 · den...
It is quite annoying to import something and it has a /// <reference no-default-lib="true" /> directive as it will remove the Deno global. Perhaps we should look into if there's...
Adamgreg
AdamgregOP16mo ago
That's awesome, thanks!

Did you find this page helpful?