Hi all, tinkering with deno and while i can get the hello world example to work I can't seem to get the more advanced demo from the homepage working:
$ deno denodemo.ts
error: Uncaught InvalidData: data did not match any variant of untagged enum ArgsEnum
What is your content of the denodemo.ts?
Straight from the website:
import { serve } from "https://deno.land/[email protected]/http/server.ts";
const s = serve({ port: 80000 });
console.log("http://localhost:80000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
I tried this from ubuntu and it didn't give the error.
I'd be curious what your deno -V is and os?
I was able to reproduce it with Deno 0.40 and 0.41. Try port 8000 instead of 80000. The largest possible port number of IPv4 and IPv6 is 65535. The code on the website is correct. They use port 8000.
Also you witll need network permission with deno --allow-net=127.0.0.1 denodemo.ts.
Yep the lower port works!
running it with deno --allow-net denodemo.ts
Hi, I got similar error, too.
My welcome.ts source code:
import { serve } from "https://deno.land/[email protected]/http/server.ts";
const s = serve({ port: 80000 });
console.log("http://localhost:80000/");
for await (const req of s) {
req.respond({ body: "Hello World\n" });
}
But after I enter deno welcome.ts or deno --allow-net=127.0.0.1 welcome.ts, still got error.
Error message:
Compile file:///.../demos/deno/welcome.ts
error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
â–º file:///.../demos/deno/welcome.ts:4:5
4 for await (const req of s) {
~~~~~
error TS2339: Property 'listenTLS' does not exist on type 'typeof Deno'.
â–º https://deno.land/[email protected]/http/server.ts:16:17
16 const { listen, listenTLS } = Deno;
~~~~~~~~~
error TS2339: Property 'errors' does not exist on type 'typeof Deno'.
â–º https://deno.land/[email protected]/http/server.ts:205:33
......
Found 16 errors.
@hylerrix What Deno version are you on? (deno —version)
@hylerrix What Deno version are you on? (deno —version)
Thx reply, can 0.38 version work? My Deno version is 0.38. And I use asdf to manage Deno version.
If you use Deno version v0.38.0, then you have to change to import path in your code to your version. There were and still are breaking changes on every new version.
https://deno.land/[email protected]/http/server.ts
Also consider upgrade your deno installation to the latest version with deno upgrade.
If you use Deno version v0.38.0, then you have to change to import path in your code to your version. There were and still are breaking changes on every new version.
https://deno.land/[email protected]/http/server.tsAlso consider upgrade your deno installation to the latest version with
deno upgrade.
Thx! That's very helpful.
Most helpful comment
I was able to reproduce it with Deno 0.40 and 0.41. Try port 8000 instead of 80000. The largest possible port number of IPv4 and IPv6 is 65535. The code on the website is correct. They use port 8000.
Also you witll need network permission with
deno --allow-net=127.0.0.1 denodemo.ts.