denoland / vscode_deno

Visual Studio Code plugin for Deno
https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno
MIT License
1.48k stars 144 forks source link

cannot find name 'Deno' #66

Closed itajaja closed 4 years ago

itajaja commented 4 years ago

image

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

image

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

shinebayar-g commented 1 year ago

Do you have an import map that maps constructs to a fully qualified URL?

Oh sorry forgot to include deno config file.

deno.jsonc

{
    "imports": {
        "cdk8s": "npm:cdk8s@2.6.43",
        "constructs": "npm:constructs@10.1.244"
    },
    "tasks": {
        "dev": "deno run --watch main.ts",
        "build": "deno run --allow-env --allow-write main.ts"
    },
    "fmt": {
        "options": {
            "indentWidth": 4,
            "lineWidth": 100,
            "singleQuote": true
        }
    }
}

deno task build command works and cdk8s yaml file works fine, it's just VSCode complaining :(

Edit: Actually I have another problem. With this import

import { KubeNamespace } from './imports/k8s.ts';

I'm getting the error.

An import path cannot end with a '.ts' extension. Consider importing './imports/k8s' instead.ts(2691)
bartlomieju commented 1 year ago

Please open a separate issue about this problem. It requires more investigation. Make sure you are using latest Deno and VSCode extension.

shinebayar-g commented 1 year ago

I had this issue, which was caused by this line in my VS Code settings.json:

"typescript.tsserver.experimental.enableProjectDiagnostics": true

I diagnosed this by starting VS Code with a blank profile (code --user-data-dir=/tmp/vscode .) and seeing that Deno support worked, so I removed lines from my VS Code config until I found the culprit.

This also fixed the error An import path cannot end with a '.ts' extension..

For some reason, removing wasn't enough, even it wasn't enabled in User settings. But explicitly disabling it in .vscode/settings.json worked. Maybe we could mention this somewhere in the extension README?

{
    "deno.enable": true,
    "deno.lint": true,
    "editor.formatOnSave": true,
    "[typescript]": {
        "editor.defaultFormatter": "denoland.vscode-deno"
    },
    "typescript.tsserver.experimental.enableProjectDiagnostics": false
}

sorry for the noise.

sjc5 commented 1 year ago

I had this issue, which was caused by this line in my VS Code settings.json: "typescript.tsserver.experimental.enableProjectDiagnostics": true I diagnosed this by starting VS Code with a blank profile (code --user-data-dir=/tmp/vscode .) and seeing that Deno support worked, so I removed lines from my VS Code config until I found the culprit. This also fixed the error An import path cannot end with a '.ts' extension..

For some reason, removing wasn't enough, even it wasn't enabled in User settings. But explicitly disabling it in .vscode/settings.json worked. Maybe we could mention this somewhere in the extension README?

{
    "deno.enable": true,
    "deno.lint": true,
    "editor.formatOnSave": true,
    "[typescript]": {
        "editor.defaultFormatter": "denoland.vscode-deno"
    },
    "typescript.tsserver.experimental.enableProjectDiagnostics": false
}

sorry for the noise.

Not noise! This worked for me, worth a try for others. Wow, weird bug.

activenode commented 12 months ago

I got the same problem though none of the above worked unfortunately.

j4tmr commented 10 months ago

I got the same problem though none of the above worked unfortunately.

same

j4tmr commented 10 months ago

Some other situations can also lead to this issue, for example, if you are using the Volar extension. This can cause a conflict with the Deno extension, as Volar, to my knowledge, involves managing TypeScript. The management of TypeScript by both can lead to conflicts, and disabling the Volar extension should resolve the issue.

joshpachner commented 10 months ago

I got the same issue. And i've tried all the recommended solutions. The weird thing is that it was finding the Deno, and then "randomly" mid coding today it stopped. 🤷‍♂️ It still runs successfully but VScode is telling me it cant find it and the red lines are driving me crazy lol

But putting /// <reference lib="deno.ns" /> at the top of my file (index.ts) worked. Some other github issue talks about how certain libraries have a /// <reference no-default-lib="true"/> which then throws everything amuck

dgreensp commented 10 months ago

@joshpachner Thank you for pointing out that a TypeScript file seemingly anywhere in your project can cause this. In my case, I think it was an NPM package in Deno's cache, which I keep checked into my repository.

JorensM commented 9 months ago

I got the same issue. And i've tried all the recommended solutions. The weird thing is that it was finding the Deno, and then "randomly" mid coding today it stopped. 🤷‍♂️ It still runs successfully but VScode is telling me it cant find it and the red lines are driving me crazy lol

But putting /// <reference lib="deno.ns" /> at the top of my file (index.ts) worked. Some other github issue talks about how certain libraries have a /// <reference no-default-lib="true"/> which then throws everything amuck

I was having this issue and your suggestion solved it, but I was also getting cannot find name 'console' when doing console.log, which is still there.

cameronraysmith commented 7 months ago

The civet extension for civet produces errors such as typescript(2307) as opposed to ts(2307) that can be difficult to track down in the context of resolving issues like those from the OP and others mentioned in this thread.

anthonyg56 commented 5 months ago

I had this issue, which was caused by this line in my VS Code settings.json: "typescript.tsserver.experimental.enableProjectDiagnostics": true I diagnosed this by starting VS Code with a blank profile (code --user-data-dir=/tmp/vscode .) and seeing that Deno support worked, so I removed lines from my VS Code config until I found the culprit. This also fixed the error An import path cannot end with a '.ts' extension..

For some reason, removing wasn't enough, even it wasn't enabled in User settings. But explicitly disabling it in .vscode/settings.json worked. Maybe we could mention this somewhere in the extension README?

{
    "deno.enable": true,
    "deno.lint": true,
    "editor.formatOnSave": true,
    "[typescript]": {
        "editor.defaultFormatter": "denoland.vscode-deno"
    },
    "typescript.tsserver.experimental.enableProjectDiagnostics": false
}

sorry for the noise.

Not noise! This worked for me, worth a try for others. Wow, weird bug.

This worked for me!

marcelarie commented 4 months ago

I still have this problem, I can't go to definition.

kyleinaction commented 3 weeks ago

I still have this problem, I can't go to definition.

I had this problem as well. I enabled deno in my local workspace but still VSCode was using it's internal typescript language server instead of deno.

I opened up my User Settings JSON (can be found in the Command Pallet Shift+Cmd/Ctrl+P) and saw a kv called "deno.enablePaths": []. I don't desire to enable/disable deno in this way, so I simply removed it entirely and voila, VSCode is now using deno for typescript files in deno-enabled workspaces. Hope this helps.

edit: For clarity, I am using the official deno.land VSCode plugin.

FunctionDJ commented 1 week ago

I had this issue, which was caused by this line in my VS Code settings.json:

"typescript.tsserver.experimental.enableProjectDiagnostics": true

I diagnosed this by starting VS Code with a blank profile (code --user-data-dir=/tmp/vscode .) and seeing that Deno support worked, so I removed lines from my VS Code config until I found the culprit.

This also fixed the error An import path cannot end with a '.ts' extension..

This worked for me. Too bad this option appears to be incompatible with Deno because i think it's very useful. It's fair that it's incompatible, given that it's an experimental feature. I hope the TS devs can get this stable soon so Deno is incentivised to support it.