Your code snippet appears to be correct, but there might be a small error in the module file on your local machine. Let me explain why:
Upon executing the code provided by you, it functions as intended:
It is worth noting that I have removed an extra console.log
statement from your initial example before calling serve(handler)
:
so-38471956.ts
:
import { serve } from "https://deno.land/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6210160511312d22222d">[email protected]</a>/http/server.ts";
function handler(_req: Request): Response {
return new Response("Hello, World!");
}
serve(handler);
% deno run --allow-net so-38471956.ts
Listening on http://localhost:8000/
Everything looks good. However, after substituting the import specifier with the one mentioned in the error message you supplied, this is the resulting error that I encountered when attempting to execute the modified program:
so-38471956.ts
:
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";
function handler(_req: Request): Response {
return new Response("Hello, World!");
}
serve(handler);
% deno run --allow-net so-38471956.ts
error: Module not found "https://deno.land/std@$STD_VERSION/http/server.ts".
at file:///Users/deno/so-38471956.ts:1:23
I suggest verifying your actual source file module. Please try copying and pasting the exact code from my initial code block into your file, save it, and then run it again using the specified command (including the net
permission argument following deno run
): this should resolve the issue.