ts-serve
ts-serve copied to clipboard
import declarations may only appear at top level of a module
Server.ts :
import { serveDirWithTs } from "jsr:@ayame113/ts-serve";
Deno.serve((request) => serveDirWithTs(request));
index.html :
<html>
<head>
<script src="Test.ts"></script>
</head>
<body></body>
</html>
Test.ts :
import {test} from "./Test2.ts"
console.log(test);
Test2.ts :
export let test=1;
Result:
Seems typescript imports dont work under Deno with ts-serve.
Seems something is wrapping the Test.ts file and so the import isnt top-level anymore,
but this is not apparent when clicking the error message as it shows the unmodified (correct) code.
Is this an issue with Deno.emit or ts-serve ?
Ah thank you for finding this!
I'll look into this.
@lukakostic
This seems to be an error coming from the browser.
How about adding type="module" to your html?
<html>
<head>
- <script src="Test.ts"></script>
+ <script src="Test.ts" type="module"></script>
</head>
<body></body>
</html>