Deno LSP doesn't recognize workspaces as imports
For some reason the vscode plugin for deno says this code is invalid even though it runs perfectly fine via the cli.
mod.ts:
deno.jsonc:
./test/mod.ts
./test/deno.jsonc
When I run mod.ts via the cli I get 3 which is expected but the vscode lsp says
Relative import path "@mypackage/test" not prefixed with / or ./ or ../
3 Replies
It seems like you're encountering an issue where the Deno Language Server in Visual Studio Code is not recognizing workspace imports. According to the documentation, Deno should automatically detect and apply an import map specified in a
deno.json
or deno.jsonc
configuration file at the root of your workspace.
However, from the configuration you've provided, it appears that you're using the workspaces
feature, which is different from import maps. The workspaces
feature is used to manage multiple Deno projects within a single repository, but it does not automatically create import aliases that can be used in your code.
To resolve the issue with the import path not being recognized, you should define an import map that specifies the aliases for your module paths. Here's what you need to do:
1. Create an import map file, for example import_map.json
, at the root of your workspace with the following content:
2. Update your deno.jsonc
file at the root of your workspace to include the import map:
3. Ensure that the Deno extension for Visual Studio Code is configured to use this import map. You can do this by setting the deno.importMap
setting in your .vscode/settings.json
file to point to your import map file:
Make sure that the path to the import_map.json
file is correct and relative to the root of your workspace. After making these changes, Deno should recognize your import map configuration, and the error message about the import path should no longer appear.
If you continue to experience issues, you may want to restart Visual Studio Code toensure that the settings are applied correctly. 🦕
@Bloxs support for workspaces is under active development and not ready for prime time yet. CLI is mostly ready, but as you noticed the lsp powering the vscode extension is not