-1

below file is named index.ts

import { serve } from "https://deno.land/std@0.166.0/http/server.ts";

function handler(_req: Request): Response {
  return new Response("Hello, World!");
}

console.log("Listening on http://localhost:8000");
serve(handler);

after running

deno run index.ts

I'm getting 404 error while downloading https://deno.land/std@$STD_VERSION/http/server.ts

Download https://deno.land/std@$STD_VERSION/http/server.ts
Download https://deno.land/std@$STD_VERSION/http/server.ts
error: Uncaught Error: Import 'https://deno.land/std@$STD_VERSION/http/server.ts' failed: 404   Not Found
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
JHBonarius
  • 10,824
  • 3
  • 22
  • 41
wiero
  • 2,176
  • 1
  • 19
  • 28

2 Answers2

0

The code in your question seems fine, but I suspect that you have a typo in the actual module file on your computer. Here's why:

When I run the code in your question, it works as expected:

Note, I removed the extra console.log statement you had in your example before the invocation of serve(handler):

so-74582168.ts:

import { serve } from "https://deno.land/std@0.166.0/http/server.ts";

function handler(_req: Request): Response {
  return new Response("Hello, World!");
}

serve(handler);

% deno run --allow-net so-74582168.ts
Listening on http://localhost:8000/

Looks good. However, when I replace the import specifier with the one in your error message, this is the error that I see in the console when I try to run the modified program:

so-74582168.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-74582168.ts
error: Module not found "https://deno.land/std@$STD_VERSION/http/server.ts".
    at file:///Users/deno/so-74582168.ts:1:23

Double-check your actual source file module. Try copying and pasting the exact code from my first code block above into your file, save it, and then run it again using the command I showed (including the net permission argument after deno run): it should work.

jsejcksn
  • 27,667
  • 4
  • 38
  • 62
0

Before installing newest deno I already had one on my machine with version 1.0.0 ( which I forgot about )

After removing old version new one was used and sample worked fine.

wiero
  • 2,176
  • 1
  • 19
  • 28