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

Relative import path "preact" not prefixed with / or ./ or ../deno(import-prefix-missing) #514

Closed
Esteban-Rocha opened this issue Jul 15, 2022 · 22 comments

Comments

@Esteban-Rocha
Copy link

Esteban-Rocha commented Jul 15, 2022

Hello! I literally just started a new project to learn Fresh and I got these issues, I wonder if anyone has any idea of what might be happening?

$ deno -V: deno 1.23.4
Installed via: curl -fsSL https://deno.land/install.sh | sh

macOS: Monterrey

settings.json

{
  "deno.enable": true,
  "deno.unstable": true
}

import_map.json

{
  "imports": {
    "$fresh/": "https://deno.land/x/[email protected]/",
    "preact": "https://esm.sh/[email protected]",
    "preact/": "https://esm.sh/[email protected]/",
    "preact-render-to-string": "https://esm.sh/[email protected][email protected]"
  }
}

Using VsCode and https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno

image

image

image

@lucacasonato
Copy link
Member

Are the files at the root of your VS Code directory?

@Esteban-Rocha
Copy link
Author

@lucacasonato Yes, they are, just a standard fresh install following the docs steps.

@ian-cavnar-g2w
Copy link

I'm having this same issue on newly created Fresh project using deno run -A -r https://fresh.deno.dev my-project.

image

@Esteban-Rocha
Copy link
Author

Yeah, definitely some issue is happening, I tried the Fresh tutorial from the docs on three different laptops, and they all have the same problem. Two of them are intel, and the other is an M1.

@kitsonk
Copy link

kitsonk commented Jul 24, 2022

What is the contents of the deno.jsonc or deno.json in the root of the project?

What is the debug output of vscode under Deno Language Server?

@Esteban-Rocha
Copy link
Author

Esteban-Rocha commented Jul 25, 2022

What is the contents of the deno.jsonc or deno.json in the root of the project?

What is the debug output of vscode under Deno Language Server?

Everything is as on the docs: https://fresh.deno.dev/docs/getting-started/create-a-project

deno.json

{
  "tasks": {
    "start": "deno run -A --watch=static/,routes/ dev.ts"
  },
  "importMap": "./import_map.json"
}

settings.json

{
  "deno.enable": true,
  "deno.unstable": true
}

import_map.json

{
  "imports": {
    "$fresh/": "https://deno.land/x/[email protected]/",
    "preact": "https://esm.sh/[email protected]",
    "preact/": "https://esm.sh/[email protected]/",
    "preact-render-to-string": "https://esm.sh/[email protected][email protected]"
  }
}
Starting Deno language server...
  version: 1.23.4 (release, aarch64-apple-darwin)
  executable: /Users/xxx/.deno/bin/deno
Connected to "Visual Studio Code" 1.69.2
Enabling import suggestions for: https://deno.land
Download https://deno.land/.well-known/deno-import-intellisense.json
Enabling import suggestions for: https://x.nest.land
Download https://x.nest.land/.well-known/deno-import-intellisense.json
Download https://intellisense.nest.land/deno-import-intellisense.json
Enabling import suggestions for: https://crux.land
Download https://crux.land/.well-known/deno-import-intellisense.json
Server ready.

@kitsonk
Copy link

kitsonk commented Jul 25, 2022

Ok, for some reason the Deno Language Server is not identifying the configuration and import map. In the logged output I would expected to see something like:

Starting Deno language server...
  version: 1.23.4 (release, x86_64-apple-darwin)
  executable: /Users/xxx/.deno/bin/deno
Connected to "Visual Studio Code" 1.69.2
  Auto-resolved configuration file: "file:///Users/xxx/deno.json"
Setting import map from configuration file: "./import-map.json"
  Resolved import map: "/Users/xxx/import-map.json"

For troubleshooting purposes, could you try to things and see if the output changes:

  • renaming the deno.json to deno.jsonc and reloading (Developer: Reload Window from the command palette)
  • adding "deno.config" option to your workspace settings pointing to the config file and reloading

@Esteban-Rocha
Copy link
Author

@kitsonk

adding "deno.config" option to your workspace settings, pointing to the config file and reloading

That worked! Thanks a lot.

I noticed something. It only worked on the settings UI of VsCode. When I added that to the settings.json of the workspace, it did not work.

Thanks for all the help. Maybe this can be added to some docs. I hit across some other people who are experiencing the same issue.

@kitsonk
Copy link

kitsonk commented Jul 26, 2022

@Esteban-Rocha what does you project structure look like? (for example is your deno.json in the root of your workspace folder in vscode?)

Are you saying adding a value to .vscode/settings.json directly didn't work (what value did you put there?) but then setting it via the UI did? What value did you use? Did you set user settings or workspace settings?

Cursor_and_Settings_—_deno_doc

@Esteban-Rocha
Copy link
Author

Esteban-Rocha commented Jul 26, 2022

@kitsonk

what does you project structure look like? (for example is your deno.json in the root of your workspace folder in vscode?)

image

Are you saying adding a value to .vscode/settings.json directly didn't work (what value did you put there?) but then setting it via the UI did?

Correct.

What value did you use?

Tried:

  • "deno.config": "./deno.json",
  • "deno.config": "deno.json",

None worked;
But then I used; ./deno.json on the UI and it worked.

Did you set user settings or workspace settings?

Workspace settings.

@kitsonk
Copy link

kitsonk commented Jul 26, 2022

Can you provide the contents of .vscode/settings.json is now with it working?

And one more favour, under the command palette run Deno: Language Server Status and provide the Workspace Settings section?

Something is clearly not working as expected, because based on everything you are demonstrating it should have just worked but clearly it hasn't.

@Esteban-Rocha
Copy link
Author

Esteban-Rocha commented Jul 27, 2022

@kitsonk

Can you provide the contents of .vscode/settings.json is now with it working?

{
  "deno.config": "./deno.json",
  "deno.enable": true,
  "deno.unstable": true
}

Deno: Language Server Status and provide the Workspace Settings section?

Dumped the full of it in case it helps.

status.md

@kitsonk
Copy link

kitsonk commented Jul 27, 2022

@Esteban-Rocha thanks for that... something strange is going on.

In the settings.json you report the value of "deno.enable" is "./deno.json" but if you look in the config you dumped, the setting is "deno.json".

Is this a multi-root workspace that you are working with?

@Esteban-Rocha
Copy link
Author

@kitsonk Hey! Yes, it seems it is.

@kitsonk
Copy link

kitsonk commented Aug 2, 2022

Ah, ok... hmmm... well, that would explain it all. 😄

  • Auto-detection of a config file doesn't work in multi-root workspaces. This is a bug and I will raise an issue about it.
  • Setting the option in settings.json in a multi-root workspace doesn't work in vscode because that tries to set it for the workspace folder, but we don't allow that setting there, it needs to be set at the overall workspace level (which is what the IDE ensures works). This isn't really a bug, though I can understand it is confusing, but if the auto-detection worked, we wouldn't have been here!

@abdelhameedalsayed
Copy link

abdelhameedalsayed commented Nov 3, 2022

Just wondering, why two imports ?

"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",

and not just one import !!

@kitsonk
Copy link

kitsonk commented Nov 3, 2022

That is the way import maps work. The first one is a specific specifier, meaning "preact" will import a specific URL (https://esm.sh/[email protected]) while preact/ is a path specifier, meaning anything following the / will be appended to the final specifier. For example preact/foo would resolve to https://esm.sh/[email protected]/foo.

@jazoom
Copy link

jazoom commented Dec 27, 2022

Thank goodness I found this issue. I have been quite confused about these errors and almost gave up on trying Deno/Fresh. At least I know the origin of the problem now, but it's actually still not working for me. I've set the path to the config in the workspace level as above.

@jazoom
Copy link

jazoom commented Dec 27, 2022

The only way I could get it working properly was to abandon using a multi-root workspace, unfortunately. Though, this didn't stop the language server from crashing.

The JS/TS language service crashed. This may be caused by a plugin contributed by one of these extensions: denoland.vscode-deno, sastan.twind-intellisense

I thought this was supposed to be disabled when the Deno language server is enabled.

@lucacasonato
Copy link
Member

Closing because multi-root workspace support is an upstream Deno issue, and not specific to Fresh.

@tiagofrancafernandes
Copy link

I'm having this same issue on newly created Fresh project using deno run -A -r https://fresh.deno.dev my-project.

image

// On VSCode just add to your ~/.config/Code/User/settings.json:

"deno.enablePaths": [
   "./worker",
]

@igl
Copy link

igl commented Jan 1, 2024

Boils down to:

  • you can only have 1 deno.json and only 1 import_map.json per vs-code window
  • enablePath is really only helpful when you have other non-deno .ts files in a project.

Closing because multi-root workspace support is an upstream Deno issue, and not specific to Fresh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants