denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.78k stars 5.34k forks source link

Code generated by `deno init` gives an error in VS Code #26489

Open mike-lischke opened 3 hours ago

mike-lischke commented 3 hours ago

deno 2.0.2 (stable, release, aarch64-apple-darwin) v8 12.9.202.13-rusty typescript 5.6.2

The generated code is as expected:

export function add(a: number, b: number): number {
  return a + b;
}

// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
if (import.meta.main) {
  console.log("Add 2 + 3 =", add(2, 3));
}

however, this gives me the error:

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.ts(1343)

Bildschirmfoto 2024-10-23 um 17 19 59

All I did was to create a new folder, opened that in VS Code and ran deno init. Then I opened main.ts and got this. Not a good first impression, even though deno main.ts (or deno run main.ts for that matter) run fine.

Further info: I have tsc 5.2.2 installed globally on my box and .vscode/settings.json just contains:

{
    "deno.enable": true
}
marvinhagemeister commented 2 hours ago

Looks like somehow the Deno extension isn't enabled in this project properly, despite the config being set. Errors from the Deno extension end with deno-ts(<number>) instead of ts(<number>).

bartlomieju commented 2 hours ago

Please make sure Deno extension is not disabled in user settings (ie. not workspace settings).

mike-lischke commented 2 hours ago

To me it looks as if the extension is active. I also have this:

Bildschirmfoto 2024-10-23 um 17 50 07

But adding "DOM" to compilerSettings/lib made the deno-ts error disappear.

And removing the tsconfig.json file I had copied from another project to get the other problem solved also fixed the ts error for the console calls. So, it's important not to have both tsconfig.json and the compiler options in deno.json.

bartlomieju commented 2 hours ago

This output is really strange - you indeed have Deno extension enabled, but in that case you should not have ts(...) because Deno extension should disable the built-in TS server.

Does the situation change is you reload the VSCode window?

mike-lischke commented 2 hours ago

No, I reloaded VS Code already multiple times. Is it correct that VS Code shows TypeScript 5.6.3 in the status bar for main.ts?

Looks like the real issue is that the built-in TS language server is not disabled for some reasons. I also get errors for imported (npm) packages.

bartlomieju commented 2 hours ago

@mike-lischke could you please go to the Output panel and select Deno Language Server? Please paste the output of it.

bartlomieju commented 1 hour ago

What might be happening - the "user settings" have Deno disabled globally, you can check that by opening Command Pallete in VSCode and going to Preferences: Open User Settings (JSON) and looking for any keys starting with deno.. If you have any there, I suggest to remove them altogether.

mike-lischke commented 1 hour ago

This is the Deno LSP output:

Starting Deno language server... version: 2.0.2 (release, aarch64-apple-darwin) executable: /Users/mike/.deno/bin/deno Connected to "Visual Studio Code" 1.94.2 Enabling import suggestions for: https://deno.land Refreshing configuration tree... Resolved Deno configuration file: "file:///Volumes/Extern/Work/projects/ANTLRng2/deno.json" Resolved .npmrc: "/Users/mike/.npmrc" Resolved lockfile: "file:///Volumes/Extern/Work/projects/ANTLRng2/deno.lock" Server ready. Refreshing configuration tree... Resolved Deno configuration file: "file:///Volumes/Extern/Work/projects/ANTLRng2/deno.json" Resolved .npmrc: "/Users/mike/.npmrc" Resolved lockfile: "file:///Volumes/Extern/Work/projects/ANTLRng2/deno.lock" Refreshing configuration tree... Resolved Deno configuration file: "file:///Volumes/Extern/Work/projects/ANTLRng2/deno.json" Resolved .npmrc: "/Users/mike/.npmrc" Resolved lockfile: "file:///Volumes/Extern/Work/projects/ANTLRng2/deno.lock"

and the LSP status might be useful:

Deno Language Server Status

Workspace Settings

{
  "enable": true,
  "disablePaths": [],
  "enablePaths": null,
  "cache": null,
  "cacheOnSave": true,
  "certificateStores": null,
  "config": null,
  "importMap": null,
  "codeLens": {
    "implementations": false,
    "references": false,
    "referencesAllFunctions": false,
    "test": false
  },
  "internalDebug": false,
  "internalInspect": false,
  "logFile": false,
  "lint": true,
  "documentPreloadLimit": 1000,
  "suggest": {
    "imports": {
      "autoDiscover": true,
      "hosts": {
        "https://deno.land": true
      }
    }
  },
  "testing": {
    "args": [
      "--allow-all",
      "--no-check"
    ]
  },
  "tlsCertificate": null,
  "unsafelyIgnoreCertificateErrors": null,
  "unstable": [],
  "javascript": {
    "inlayHints": {
      "parameterNames": {
        "enabled": "none",
        "suppressWhenArgumentMatchesName": true
      },
      "parameterTypes": {
        "enabled": true
      },
      "variableTypes": {
        "enabled": false,
        "suppressWhenTypeMatchesName": true
      },
      "propertyDeclarationTypes": {
        "enabled": false
      },
      "functionLikeReturnTypes": {
        "enabled": true
      },
      "enumMemberValues": {
        "enabled": true
      }
    },
    "preferences": {
      "importModuleSpecifier": "shortest",
      "jsxAttributeCompletionStyle": "auto",
      "autoImportFileExcludePatterns": [],
      "useAliasesForRenames": true,
      "quoteStyle": "double"
    },
    "suggest": {
      "completeFunctionCalls": false,
      "includeAutomaticOptionalChainCompletions": true,
      "includeCompletionsForImportStatements": true,
      "names": true,
      "paths": true,
      "autoImports": true,
      "enabled": true,
      "classMemberSnippets": {
        "enabled": true
      },
      "objectLiteralMethodSnippets": {
        "enabled": true
      }
    },
    "updateImportsOnFileMove": {
      "enabled": "always"
    }
  },
  "typescript": {
    "inlayHints": {
      "parameterNames": {
        "enabled": "none",
        "suppressWhenArgumentMatchesName": true
      },
      "parameterTypes": {
        "enabled": false
      },
      "variableTypes": {
        "enabled": false,
        "suppressWhenTypeMatchesName": true
      },
      "propertyDeclarationTypes": {
        "enabled": false
      },
      "functionLikeReturnTypes": {
        "enabled": false
      },
      "enumMemberValues": {
        "enabled": false
      }
    },
    "preferences": {
      "importModuleSpecifier": "shortest",
      "jsxAttributeCompletionStyle": "auto",
      "autoImportFileExcludePatterns": [],
      "useAliasesForRenames": true,
      "quoteStyle": "double"
    },
    "suggest": {
      "completeFunctionCalls": false,
      "includeAutomaticOptionalChainCompletions": true,
      "includeCompletionsForImportStatements": true,
      "names": true,
      "paths": true,
      "autoImports": true,
      "enabled": true,
      "classMemberSnippets": {
        "enabled": true
      },
      "objectLiteralMethodSnippets": {
        "enabled": true
      }
    },
    "updateImportsOnFileMove": {
      "enabled": "always"
    }
  }
}