Vscode_deno: cannot find name 'Deno'

Created on 28 May 2020  Â·  33Comments  Â·  Source: denoland/vscode_deno

image

imports seem to work correctly, deno seems to be running:

image

I didn't change any settings. what am I missing?

Most helpful comment

If you still have errors like Cannot find name 'Deno'. ts(2304), try the following:

View > Command Palette... > deno: Init > Enable deno lint? Yes

Deno is now set up. You can enable and disable settings (like --unstable) in the .vscode/settings.json file. Before the extension will work you need to reload VS Code.

Click on Reload window

vscode/settings.json will contain:

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

If you still have errors like Could not find module "https://deno.land/..." locally. Deno Language Server(1005), try the following:

View > Command Palette... > deno: Restart Deno Language Server

All 33 comments

you can upgrade
image

Same here...
image

Deno output:

Found deno, version:
deno: 1.0.2
v8: 8.4.300
typescript: 3.9.2

Screenshot_41
Screenshot_40
Deno is not found

you can upgrade

no, I am already using the latest version of the right plugin, not the deprecated one

I had the same issue and it looks like when I install the extension from vs marketplace the typescript-deno-plugin version running is v1.29.0 😕

I've pulled the repo and build it locally then I've installed the .vsix manually and now it's working and it's running typescript-deno-plugin v1.31.0. Not ideal but it's working (at least for me 😛)

Yes, this happens to me too, the denoland plugin doesn't work at all while the deprecated justjavac does.

I encounter this issue on the latest VSCode 1.45.1 on Mac. And I just figured out and resolve the problem by upgrade the global tsc to latest 3.9.3 and config VSCode to use that version with "typescript.tsdk".

I guess that was due to the VSCode inline tsc 3.8.3 didn't work well with deno's plugin, while deno's inline one is 3.9.2.

QQ20200601-115435

Checkout this link https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-newer-typescript-versions for the steps.

I'm using latest VSCode Insider which also uses latest Typescript 3.9.4, and the denoland version of the extension doesn't work anyway (No import and no Deno namespace, but deno in the status bar). Both deprecated versions of the extension works (justjavac and axetroy).

Maybe this answer is helpful, configuring Deno types in VS Code.

Currently, this is a working solution for me with the built-in TypeScript version of VS Code 1.45.1. If you need to configure a custom workspace version, there are some more steps to do - take a look at the docs here.

I am seeing this issue too. I tried all the above solutions to no avail. I don't imagine this is intended behavior.

you can upgrade
image

I think a number of people misunderstood this comment. It turns out the deprecated deno plugin by justjavac actually has a newer release than the official plugin (this one) - it worked for me.

you can upgrade
image

I think a number of people misunderstood this comment. It turns out the deprecated deno plugin by justjavac actually has a newer release than the official plugin (this one) - it worked for me.

Not sure I would say that the comment was misunderstood. Seems pretty clear and it should probably be changed? Regardless, this solution worked for me as well

nope, I have the new one, still deno doesn't work:
image

@itajaja , That's the problem, the "new" one is old (1.24.0), and the deprecated is newer (1.34.0). In other words, the extension from denoland doesn't work yet, but the extension from justjavac does, but you'll get a annoying deprecation popup on startup.

I see, thanks for the clarification. well, since this is still the repo for the "new" one, the new one still has this bug that needs to be solved

@itajaja , That's the problem, the "new" one is old (1.24.0), and the deprecated is newer (1.34.0). In other words, the extension from denoland doesn't work yet, but the extension from justjavac does, but you'll get a annoying deprecation popup on startup.

So is there an expected timeline for the official plugin to issue an update?

reverting to the deprecated plugin until this issue is resolved

Note that you may have to reinstall the extension to get this fix (I did, even though I newly installed it).

Im facing the same issue. i installed latest Deno 1.4.6 version and denoland.vscode-deno extension. What is solution to this error??

@rshashik restart your ide - what have you tried so far?

@rshashik restart your ide - what have you tried so far?

1) installed deno 1.4.6
2) installed denon v2.4.4
3) installed denoland.vscode-deno extension in my mac
4) created .vscode/settings.json file and set "deno.enable": true
5) created server.ts file
`import { Application } from "https://deno.land/x/oak/mod.ts";
import router from "./routes.ts";
const port = Deno.env.get("PORT") || 5000;

const app = new Application();

app.use(router.routes());
app.use(router.allowedMethods());

console.log(Server running on port ${port});

await app.listen({ port: +port });`

Error in my vscode editor at Deno.env.get("PORT"): Cannot find name 'Deno'.ts(2304)
https://github.com/rshashik/pdr.git

@rshashik did you restart your IDE? Can you check the extension is enabled? Can you check it’s the correct link (click the link in the readme)?

@rshashik
are you sure your settings.json is valid?
for me it works, same versions as you + .vscode/settings.json:
{ "deno.enable": true }

after - restart IDE and it works (for me)

I'm also encountering this issue.

I can see that the deno extension is doing something, since as soon as I set it to "deno.enable": false in my settings.json I get the An import path cannot end with a '.ts' extension. Consider importing [...] .ts(2691)

But when I set "deno.enable": true those import errors disappear but I still have Cannot find name 'Deno'. Types seems to default to any everywhere, and development is a pain.

The very odd thing is that, sometime, and I've not been able to figure exactly how, through a combination of activating / deactivating the extension, changing code in my project, restarting the TS server, restarting the deno language server, it starts to work properly…

But whenever I leave vscode and come back to the project, its broken again :(

I've tried disabling most of my vscode extensions without success… The issue is there for me, and I think it's a nasty one to figure out if some people never experience it :/

Same issue as in the OP, plus it doesn't pick up on cached modules.
deno info some_file.ts correctly reports cached dependencies and their respective dependency trees. The scripts also run/bundle/install just as expected.

Deno.something(...) reports Cannot find name 'Deno'.ts(2304)
and
import { some_module } from 'some_url'; reports Could not find module "some_url" locally.Deno Language Server(1005)

Environment (An ubuntu vm basically set up from scratch just to test deno out):
-Fresh ubuntu 20.04.1 installation.
-Fresh VSCode 1.15.1
-Fresh deno installation 1.4.6
-Deno extension 2.3.3

.vscode/settings.json:

{
    "deno.enable": true,
    "deno.unstable": false,
    "editor.formatOnSave": true,
    "editor.formatOnPaste": true,
}

The extension is enabled in VSCode. The deprecated version (justjavac.vscode-deno) does not show the behavior for Deno.something but fails to pick up on the cached modules too.

If you still have errors like Cannot find name 'Deno'. ts(2304), try the following:

View > Command Palette... > deno: Init > Enable deno lint? Yes

Deno is now set up. You can enable and disable settings (like --unstable) in the .vscode/settings.json file. Before the extension will work you need to reload VS Code.

Click on Reload window

vscode/settings.json will contain:

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

If you still have errors like Could not find module "https://deno.land/..." locally. Deno Language Server(1005), try the following:

View > Command Palette... > deno: Restart Deno Language Server

Thanks for the answer. Following the instructions, the second half worked great and vscode now correctly reports the modules as known. Unfortunately it is still unaware of the Deno namespace and reports the familiar error. I recorded the steps, just in case, and you can look at the behavior here: https://streamable.com/cz2fkl

Another thing of note is that in tsconfig.json

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "rootDirs": [
            "./src",
            "./tests"
        ]
    }
}

vscode reports
File '$HOME/.cache/deno/lib.deno.unstable.d.ts' not found.ts
which probably is a more suitable hint at the cause here.

@nitowa: are you sure Deno is correctly installed ?

$ deno info
DENO_DIR location: "$HOME/.deno"
Remote modules cache: "$HOME/.deno/deps"
TypeScript compiler cache: "$HOME/.deno/gen"

lib.deno.unstable.d.ts should be found in $HOME/.deno, not in $HOME/.cache/deno.
Deno <version> should be showed at lower right of VSCode status bar eg TypeScript 4.1.2 Deno 1.5.4.

Check your $DENO_DIR envvar which should be set to $HOME/.deno

BTW, in your video, there is an Unexpected end of JSON inputerror, probably in tsconfig.json.

HTH,
Pierre

The project I'm testing with is pretty much https://github.com/lampewebdev/deno-boilerplate unmodified. Not sure where the unexpected end of JSON came from, but tsconfig.json just reports the error from the previous post (and fwiw is valid json).

deno info yields
DENO_DIR location: "$HOME/snap/deno/15/.cache/deno"
Remote modules cache: "$HOME/snap/deno/15/.cache/deno/deps"
TypeScript compiler cache: "$HOME/snap/deno/15/.cache/deno/gen"

which deno
/snap/bin/deno

deno -V
deno 1.4.6

$DENO_DIR was in fact not set at all, but even after manually setting it, the error persists. Deno was installed via snap

Deno (without version) in status bar indicates that deno executable cannot be found in path.
Otherwise, Deno <version> is displayed in status bar.

DENO-DIR is used to locate both lib.deno.d.ts and lib.deno.unstable.d.ts files.
At start, those files will be created automatically.

If Cannot find name 'Deno'. ts(2304) error persists, restart VSCode window.

If you still have errors like Cannot find name 'Deno'. ts(2304), try the following:

View > Command Palette... > deno: Init > Enable deno lint? Yes

Deno is now set up. You can enable and disable settings (like --unstable) in the .vscode/settings.json file. Before the extension will work you need to reload VS Code.

Click on Reload window

vscode/settings.json will contain:

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

If you still have errors like Could not find module "https://deno.land/..." locally. Deno Language Server(1005), try the following:

View > Command Palette... > deno: Restart Deno Language Server

It works for me fine. Thank you!

i had the same issue what worked for me was to press Ctrl+Shit+p in VS Code then Type Deno in the search. And click Deno Initialize workspace

Was this page helpful?
0 / 5 - 0 ratings