lielmus
lielmus2w ago

error: Relative import path "@std/http/file-server" not prefixed with / or ./ or ../

I'm following this documentation to create a static files server https://docs.deno.com/examples/file_server_tutorial/ There seems to be problem with the first line of the code, which is import { serveDir } from "@std/http/file-server"; I am getting the error error: Relative import path "@std/http/file-server" not prefixed with / or ./ or ../ hint: If you want to use a JSR or npm package, try running deno add jsr:@std/http/file-server or deno add npm:@std/http/file-server Which seems very strange to me, as its a standard library import, not anything relative. What am I doing wrong?
Deno
Write a file server
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
3 Replies
lielmus
lielmusOP2w ago
Do I need to use deno add even when using standard lib features?
coty
coty2w ago
You can prepend with jsr: if you don’t want to deno add
©TriMoon™
©TriMoon™2w ago
imports need an file to import from in Javascript/es-modules at all times. The standard lib is a collection of modules, that you can use but are not build-in into deno, so you need one of these in your deno.json: -
{
"imports": {
"@std": "jsr:@std"
}
}

{
"imports": {
"@std": "jsr:@std"
}
}

-
{
"imports": {
"@std": "npm:@std"
}
}

{
"imports": {
"@std": "npm:@std"
}
}

Or prefix it directly with jsr: or npm: in your module, like coty said above... - See also: https://docs.deno.com/runtime/fundamentals/configuration/#dependencies
Deno
deno.json and package.json
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno

Did you find this page helpful?