fresh icon indicating copy to clipboard operation
fresh copied to clipboard

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

Open Esteban-Rocha opened this issue 2 years ago • 15 comments

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

Esteban-Rocha avatar Jul 15 '22 22:07 Esteban-Rocha

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

lucacasonato avatar Jul 17 '22 21:07 lucacasonato

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

Esteban-Rocha avatar Jul 20 '22 19:07 Esteban-Rocha

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

image

ian-cavnar-g2w avatar Jul 22 '22 23:07 ian-cavnar-g2w

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.

Esteban-Rocha avatar Jul 23 '22 03:07 Esteban-Rocha

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?

kitsonk avatar Jul 24 '22 00:07 kitsonk

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.

Esteban-Rocha avatar Jul 25 '22 13:07 Esteban-Rocha

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

kitsonk avatar Jul 25 '22 22:07 kitsonk

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

Esteban-Rocha avatar Jul 25 '22 22:07 Esteban-Rocha

@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

kitsonk avatar Jul 26 '22 00:07 kitsonk

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

Esteban-Rocha avatar Jul 26 '22 02:07 Esteban-Rocha

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.

kitsonk avatar Jul 26 '22 02:07 kitsonk

@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

Esteban-Rocha avatar Jul 27 '22 05:07 Esteban-Rocha

@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?

kitsonk avatar Jul 27 '22 05:07 kitsonk

@kitsonk Hey! Yes, it seems it is.

Esteban-Rocha avatar Aug 02 '22 00:08 Esteban-Rocha

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!

kitsonk avatar Aug 02 '22 00:08 kitsonk

Just wondering, why two imports ?

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

and not just one import !!

abdelhameedalsayed avatar Nov 03 '22 10:11 abdelhameedalsayed

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.

kitsonk avatar Nov 03 '22 22:11 kitsonk

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 avatar Dec 27 '22 01:12 jazoom

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.

jazoom avatar Dec 27 '22 01:12 jazoom

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

lucacasonato avatar Jan 12 '23 20:01 lucacasonato

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",
]

tiagofrancafernandes avatar Apr 21 '23 14:04 tiagofrancafernandes