Nehu
Nehu11mo ago

`deno lsp` does not understand bare imports without prefix

Even in minimal project, freshly created from a template, Deno marks imports as errors and doesn't understand them. E.g. deno run --allow-read --allow-write --allow-env npm:create-vite-extra@latest" Open src/main.ts in the editor which uses deno lsp, and an error pops up:
import { createApp } from 'vue'
import { createApp } from 'vue'
Relative import path "vue" not prefixed with / or ./ or ../
(import-prefix-missing)
Relative import path "vue" not prefixed with / or ./ or ../
(import-prefix-missing)
Adding a source map doesn't make a difference. Any ideas?
2 Replies
Deno AI Helper
Deno AI Helper11mo ago
Based on the documentation, Deno does not support importing via a bare specifier (like import { createApp } from 'vue') without an import map. If you attempt to do so and the bare specifier matches a Node.js built-in module not found in an import map, Deno will provide a helpful error message asking if you meant to import with the node: prefix. If you are using code both with Deno and Node.js, the node: scheme will work in both runtimes and it’s recommended to update to them for your Node.js code anyway. You can specify imports and scopes keys in your configuration file and Deno will automatically start treating the configuration file as an import map. Here is an example of how to do this:
{
"imports": {
"vue/": "https://deno.land/x/vue@2.6.12/"
}
}
{
"imports": {
"vue/": "https://deno.land/x/vue@2.6.12/"
}
}
Then you can import Vue like this:
import { createApp } from "vue/index.js";
import { createApp } from "vue/index.js";
Please note that the documentation recommends using regular, non-bare specifiers (relative or absolute file / http URLs) for library authors; otherwise the users of the library will manually need to add your libraries (and your libraries dependencies) bare specifiers into their import map. 🦕
Sorikairo
Sorikairo11mo ago
If you are using a Jetbrains IDE, it’s a Deno plugin issue