fresh
fresh copied to clipboard
Relative import path "preact" not prefixed with / or ./ or ../deno(import-prefix-missing)
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


Are the files at the root of your VS Code directory?
@lucacasonato Yes, they are, just a standard fresh install following the docs steps.
I'm having this same issue on newly created Fresh project using deno run -A -r https://fresh.deno.dev my-project
.
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.
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?
What is the contents of the
deno.jsonc
ordeno.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.
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
todeno.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
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 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?
@kitsonk
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?
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.
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
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.
@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 Hey! Yes, it seems it is.
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!
Just wondering, why two imports ?
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/",
and not just one import !!
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
.
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.
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.
Closing because multi-root workspace support is an upstream Deno issue, and not specific to Fresh.
I'm having this same issue on newly created Fresh project using
deno run -A -r https://fresh.deno.dev my-project
.
// On VSCode just add to your ~/.config/Code/User/settings.json:
"deno.enablePaths": [
"./worker",
]