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

imports from deno.json causing deno(import-prefix-missing) in multi-root workspaces #845

Closed
KrofDrakula opened this issue May 2, 2023 · 10 comments
Assignees
Labels
bug Something isn't working high priority import maps

Comments

@KrofDrakula
Copy link

KrofDrakula commented May 2, 2023

To Reproduce

NOTE: This works when opening a deno project in an exclusive VS Code window. Using this in a multi-root project breaks.

After enabling Deno for the workspace, use the following deno.json configuration:

{
  "imports": {
    "streams/": "https://deno.land/[email protected]/streams/"
  }
}

In a file in the workspace, try importing the bare identifier:

import { TextLineStream } from "streams/text_line_stream.ts";
new TextLineStream(); // just to avoid the warning

Running this file with Deno works as expected, so the import identifier works.

Expected behavior

Import maps should resolve using the LSP in the editor to match how Deno runs.

Screenshots

image

Versions

vscode: 1.77.3
deno: 1.33.1
extension: 3.17.0

@KrofDrakula KrofDrakula changed the title imports from deno.json causing deno(import-prefix-missing) imports from deno.json causing deno(import-prefix-missing) in multi-root workspaces May 5, 2023
@KonghaYao
Copy link

Hello, when I encountered this issue, I checked the official documentation and solved it in this way.
image

@KrofDrakula
Copy link
Author

@KonghaYao imports within deno.json are detected automatically without having to set that configuration value. The problem is not in a single-root workspace like you have in your example — I've already mentioned this in the original description.

The problem are multi-root workspaces.

@jeslinmx
Copy link

Hi @KrofDrakula,

Can I check if you performed any special configuration to allow this to work in a single-root workspace? Based on the comment by @KonghaYao, #718, #805, #833, and my own usage, it seems to be broken there as well.

@KrofDrakula
Copy link
Author

@jeslinmx No, I just opened a new window (which I guess creates a blank workspace that I don't save) and the Deno project within in as a folder, no special configuration necessary for me.

@leighmcculloch
Copy link

NOTE: This works when opening a deno project in an exclusive VS Code window. Using this in a multi-root project breaks.

This issue happens in another case: when a new window is opened for an empty directory, when building a new single-root project. After adding the deno.json file with an import, the same error displays about import prefixes. The deno extension fails to pickup the imports from the deno.json file. Reloading the window gets it working again.

Screenshot 2023-07-08 at 10 26 06 PM

@bartlomieju
Copy link
Member

Thanks for the report folks. Do you still experience these problems with Deno v1.35? There were several improvements to the import map handling in the LSP and I'm wondering if this problem still persists.

@leighmcculloch
Copy link

I'm experiencing these problems with Deno v1.35.0, Deno VSCode Extension v3.19.1. Note I don't see this error when building with Deno v1.35.0 on the command line. I only see the issue in VSCode.

@bartlomieju bartlomieju added bug Something isn't working high priority and removed needs info labels Jul 11, 2023
@luisfontes
Copy link

luisfontes commented Jul 11, 2023

Experiencing the same issue on Deno v1.35.0. I had it "working" by using
"deno.config": "./path/to/folder/deno.json",
in the code-workspace file. Not a fix though

@bartlomieju bartlomieju mentioned this issue Jul 11, 2023
17 tasks
@dsherret dsherret self-assigned this Jul 19, 2023
@kaiba42
Copy link

kaiba42 commented Jul 26, 2023

+1 on this issue. I've got a limited understanding, but perhaps it's worthwhile to consider enabling the deno.importPath setting in .vscode/settings.json files within the folders specified in a multi-root workspace (.vscode/projects.code-workspace)

For example

// workspace/.vscode/projects.code-workspace
{
  "folders": [
    {
      "name": "Workspace",
      "path": "../"
    },
    {
      "name": "Project 1",
      "path": "../project1"
    },
    {
      "name": "Project 2",
      "path": "../project2"
    }
  ],
  "settings": {
    // Deno
    "deno.enable": true,
    "deno.enablePaths": ["./project1", "./project2"],
    "deno.unstable": true,
    "deno.suggest.imports.autoDiscover": true,
    "deno.lint": true,
    "deno.path": "./.devenv/profile/bin/deno",
    // -- This doesn't work today because it can only be specified for a single project --
    // "deno.importMap": "./project1/deno.jsonc",
  }
}
// workspace/project1/.vscode/settings.json
{
    "deno.enable": true,
    "deno.importPath": "./deno.jsonc" // <----------- ADD SUPPORT FOR THIS
    "[typescript]": {
        "editor.defaultFormatter": "denoland.vscode-deno"
    }
}

@nayeemrmn
Copy link
Collaborator

Closing in favour of #787.

@nayeemrmn nayeemrmn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority import maps
Projects
None yet
Development

No branches or pull requests

9 participants