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

Code generated by deno init gives an error in VS Code #1190

Closed
mike-lischke opened this issue Oct 23, 2024 · 13 comments
Closed

Code generated by deno init gives an error in VS Code #1190

mike-lischke opened this issue Oct 23, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@mike-lischke
Copy link

mike-lischke commented Oct 23, 2024

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
Copy link
Contributor

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>).

@marvinhagemeister marvinhagemeister added the bug Something isn't working label Oct 23, 2024
@bartlomieju
Copy link
Member

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

@mike-lischke
Copy link
Author

mike-lischke commented Oct 23, 2024

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
Copy link
Member

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
Copy link
Author

mike-lischke commented Oct 23, 2024

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
Copy link
Member

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

@bartlomieju
Copy link
Member

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
Copy link
Author

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"
    }
  }
}

@mike-lischke
Copy link
Author

Oha, there was indeed a deno.enabled: false entry in the user settings. How did that end up there? And why did my workspace setting not override it? But anyway, removing the user setting didn't not change a bit. After restart of VSC I have that 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.
successfully cancelled request with ID: 1
successfully cancelled request with ID: 3
successfully cancelled request with ID: 6
successfully cancelled request with ID: 10
successfully cancelled request with ID: 11
successfully cancelled request with ID: 12
successfully cancelled request with ID: 13
successfully cancelled request with ID: 14

@nayeemrmn nayeemrmn transferred this issue from denoland/deno Oct 23, 2024
@nayeemrmn
Copy link
Collaborator

Check your user settings for "typescript.tsserver.experimental.enableProjectDiagnostics": true, and disable it. Those errors are coming from the built-in TS server, and our plugin can't supress errors caused by that setting.

Please verify if that was the problem.

@mike-lischke
Copy link
Author

That was it @nayeemrmn! Removing this key from the settings.json file made the TS diagnostics go away.

@mike-lischke
Copy link
Author

Thanks for analyzing this problem with me. It's obviously a user-generated problem. Would be good if this setting could be checked by the extension and a warning be shown to inform the user about possible conflicts. Thanks!

@nayeemrmn
Copy link
Collaborator

@mike-lischke No problem! I've already opened a PR for this: #1191.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants