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

VS Code: "Not prefixed with... and not in import map from ..." #23835

Closed
saeho opened this issue May 15, 2024 · 13 comments
Closed

VS Code: "Not prefixed with... and not in import map from ..." #23835

saeho opened this issue May 15, 2024 · 13 comments
Labels
needs info needs further information to be properly triaged

Comments

@saeho
Copy link

saeho commented May 15, 2024

Version: Deno 1.14.3

Hello,

I have a VS code issue where import-map configured NPM packages are showing as errors. I saw a few threads like this but none of the threads I read solved my problem (even though the issues were very similar.

Here's an example:

On the Server Deno repo
This will show as an error in VS Code ("not prefixed with / and not in import map from..."):

import { ApolloServer } from '@apollo/server';

This is my deno.json:

"imports": {
    "@apollo/server": "npm:@apollo/server@^4.10.4",
    "graphql": "npm:graphql@^16.8.1"
  }

However, this exact imports map works in my Fresh Deno app repo and VS Code does not complain.

@lucacasonato
Copy link
Member

Is the deno.json at the root of your repo? Do you have a repo I can take a look at?

@lucacasonato lucacasonato added the needs info needs further information to be properly triaged label Jun 8, 2024
@saeho
Copy link
Author

saeho commented Jun 9, 2024

Yes, deno.json is at the root, and deno.json file works properly as it should. All the imports does the job properly, it's just VS Code that fails.

You can take a look at the repo but it's private. Can I give you private access?

@lucacasonato
Copy link
Member

Sure, can you invite @nayeemrmn and @nathanwhit?

@nayeemrmn
Copy link
Collaborator

If you're using deno.enablePaths ensure it contains the deno.json.

@nayeemrmn
Copy link
Collaborator

Also, try running deno upgrade.

@saeho
Copy link
Author

saeho commented Jun 9, 2024

Invited both Nathanwhit and Nayeermrmn.

Also tried deno upgrade, it didn't change anything for me.

@nayeemrmn
Copy link
Collaborator

@saeho I don't see anything wrong with it, it should work. What does the output panel say when you start the language server? Open it by clicking on the Deno part of the status bar at the bottom right.

@saeho
Copy link
Author

saeho commented Jun 9, 2024

@saeho I don't see anything wrong with it, it should work. What does the output panel say when you start the language server? Open it by clicking on the Deno part of the status bar at the bottom right.

It says:

Refreshing configuration tree...
  Resolved Deno configuration file: "file:///Users/saeho/Documents/apps/app-server/deno.json"
  Resolved lockfile: "file:///Users/saeho/Documents/apps/app-server/deno.lock"
  Resolved import map from configuration file
  Resolved Deno configuration file: "file:///Users/saeho/Documents/apps/app-web/deno.json"
  Resolved import map from configuration file
Server ready.
Error caching: Relative import path "preact/jsx-runtime" not prefixed with / or ./ or ../ and not in import map from "data:application/typescript;base64,aW1wb3J0ICdwcmVhY3QvanN4LXJ1bnRpbWUnOw=="
    at data:application/typescript;base64,aW1wb3J0ICdwcmVhY3QvanN4LXJ1bnRpbWUnOw==:1:8
    ```

@nayeemrmn
Copy link
Collaborator

@saeho The project folder you're using there is above the one you gave us access to. What's the path of your project root? Are you using a multiroot workspace? Currently we don't have full support for monorepos with multiple deno.jsons

If your project root is file:///Users/saeho/Documents/apps/, I suggest having a file:///Users/saeho/Documents/apps/deno.json which has all the mappings from both projects.

@saeho
Copy link
Author

saeho commented Jun 9, 2024

Path of the project is "file:///Users/saeho/Documents/apps/app-web/" and "file:///Users/saeho/Documents/apps/app-web/deno.json" is the correct path. And there is only 1 deno.json file.

I changed the path name and changed it to "app-web" instead of "name"

@saeho
Copy link
Author

saeho commented Jun 9, 2024

@saeho The project folder you're using there is above the one you gave us access to. What's the path of your project root? Are you using a multiroot workspace? Currently we don't have full support for monorepos with multiple deno.jsons

If your project root is file:///Users/saeho/Documents/apps/, I suggest having a file:///Users/saeho/Documents/apps/deno.json which has all the mappings from both projects.

Can you clarify what multiroot workspace is?

I'm using VS Code and i have 2 repos on the side so i can switch between 2 repos without changing VS Code tabs.

But the 2 repos are separate and not connected in any way.

@nayeemrmn
Copy link
Collaborator

I'm using VS Code and i have 2 repos on the side so i can switch between 2 repos without changing VS Code tabs.

Okay, yeah that's the issue. This is a multi-root workspace and they share a language server. Only the deno.json from your topmost project will be used for both currently. You can temporarily merge your other import map into that one.

@saeho
Copy link
Author

saeho commented Jun 9, 2024

Okay, that explains it all then.

Thank you.

A future update for this feature would be greatly appreciated.

@saeho saeho closed this as completed Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info needs further information to be properly triaged
Projects
None yet
Development

No branches or pull requests

3 participants