Skip to content
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

Cannot find name 'Deno'. deno-ts(2304) #841

Closed
JHarrisGTI opened this issue Apr 24, 2023 · 11 comments
Closed

Cannot find name 'Deno'. deno-ts(2304) #841

JHarrisGTI opened this issue Apr 24, 2023 · 11 comments
Labels
bug Something isn't working high priority maybe fix available Might have been fixed already

Comments

@JHarrisGTI
Copy link

I'm opening a file in a previously-working project. When I call Deno.readFile, "Deno" gets a red squiggly underline with this message:

Cannot find name 'Deno'. deno-ts(2304)

My .vscode/settings.json is:

{
    "deno.enable": true,
    "deno.unstable": true
}

I've read #66 and #466 looking for fixes. I'm using Deno 1.32.5, TypeScript 5.0.3, and VSCode extension 3.17.0 on MacOS 13.3.1 (Intel). Things I've tried:

  • Uninstalling and reinstalling the VSCode plugin
  • Restarting the language server
  • Restarting VSCode
  • Deleting my .vscode/settings.json and running Deno: Initialize Workspace Configuration
  • Disabling/reenabling deno.enable
  • Disabling/reenabling deno.unstable
  • Disabling/reenabling deno.lint
  • Running brew upgrade deno

I don't have a tsconfig.json file or anything else; the TypeScript file I'm working on is standalone aside from importing an NPM library and reading/writing some PDF files.

Deno language server output looks fine.
Starting Deno language server...
  version: 1.32.5 (release, x86_64-apple-darwin)
  executable: /usr/local/bin/deno
Connected to "Visual Studio Code" 1.77.3
Enabling import suggestions for: https://crux.land
Enabling import suggestions for: https://x.nest.land
Download https://x.nest.land/.well-known/deno-import-intellisense.json
Download https://intellisense.nest.land/deno-import-intellisense.json
Enabling import suggestions for: https://deno.land
Server ready.
@alexandruradovici
Copy link

+1

@captainbuckkets
Copy link

captainbuckkets commented May 2, 2023

#66 (comment)

Init workspace in vs code

@JHarrisGTI
Copy link
Author

#66 (comment)

Init workspace in vs code

I've done that several times, to no avail.

@denyzhirkov
Copy link

denyzhirkov commented Jun 16, 2023

+1
!Update:
Maybe it could help. So I have the same issue and was playing with the options/setting with "Deno.enable" in VSCode so found that I have "Deno: Enable Paths" with the ".cicada" option. So I removed it and thats it! Now it works.

@bartlomieju bartlomieju mentioned this issue Jul 11, 2023
17 tasks
@bartlomieju
Copy link
Member

We are investigating this issue.

Current hypothesis is that the problem manifests itself when "triple-slash directives" are used:

/// <reference lib="foo" />

A temporary workaround should be to add:

/// <reference lib="deno.ns" />

That said we are investigating a better solution that at least suggests users to add that directive in certain scenarios.

@JHarrisGTI
Copy link
Author

After some experimentation, I've determined that in my project, the problem is caused by this line of code:

import { EmbedPdf } from "https://deno.land/x/embed_pdf@v1.3.0/mod.js";

Commenting out this line and using VSCode's "Developer: Reload Window" command suppresses the problem.

That file does indeed have triple-slash directives in it, so I think you're on the right track.

@bartlomieju
Copy link
Member

FYI denoland/deno#19825 improves the diagnostics and was released in Deno v1.35.2. Please try it and let me know if that helps.

@bartlomieju bartlomieju added maybe fix available Might have been fixed already and removed needs investigation labels Jul 20, 2023
@JHarrisGTI
Copy link
Author

I'm now seeing this error message:

Cannot find name 'Deno'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'deno.ns' or add a triple-slash directive to your entrypoint: /// <reference lib="deno.ns" />

The more detailed error message is helpful, thank you! I'm not sure where I would change my compiler options, or what "entrypoint" means in this context.

Adding that directive to the file I'm working on does not reliably fix the problem, I'm afraid.

For reference, here's the file I'm working on.

import { readCSVObjects } from "https://deno.land/x/csv@v0.8.0/mod.ts";
import { EmbedPdf } from "https://deno.land/x/embed_pdf@v1.3.0/mod.js";

/// <reference lib="deno.ns" />

export async function getPayload() {
const file = await Deno.open("./test payload.csv");

	let payload;
	for await (const obj of readCSVObjects(file, { lineSeparator: "\r" })) {
		payload = obj;
	}

	file.close();

	return payload;
}

@dsherret
Copy link
Member

dsherret commented Aug 1, 2023

@JHarrisGTI move the /// <reference lib="deno.ns" /> to the top of the file. I'll update the message.

The issue is happening because of that library has a /// <reference no-default-lib="true"/>:

https://github.com/ayame113/embed-pdf-element/blob/main/mod.js#L3

@bartlomieju
Copy link
Member

With denoland/deno#20009 shipping in Deno v1.36 this week, can we close this issue?

@JHarrisGTI
Copy link
Author

Yes, moving the directive to the top of the file fixes the issue. And the new message makes that clear. Thank you for fixing this issue! 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority maybe fix available Might have been fixed already
Projects
None yet
Development

No branches or pull requests

6 participants