I am completely new to web development (coming from C#).
My current goal is to set up a very basic website to play around with Typescript.
My current attempt has the same structure as described in this Tutorial: https://youtu.be/H91aqUHn8sE
In addition I cloned this repository into my src folder and hit npm install to get all the dependencies: https://github.com/mharj/minecraft-ping
I have set up an express server to serve the dist folder:
const express = require('express');
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "./Test-With-Modules/dist")));
app.listen(3000, () => { console.log("App listening on port 3000"); })
That seems to be working fine. (serving all files from the dist folder)
I created a small index.html in my dist folder:
<head>
<head>
<script type="module" src="index.js"></script>
</head>
<body>
Hello World.
</body>
</head>
With my index.js consisting of:
import { ping } from "./minecraft-ping/src/index.js";
const data = await ping('eu.mineplex.com');
console.log(data);
//# sourceMappingURL=index.js.map
If I open the website on my browser, I get this error:
Uncaught SyntaxError: import not found: ping
despite the other index.js exporting it.
I am currently a bit confused about the module system... So any help is apreciated. <3
Learn how to setup Node.js with TypeScript while supporting native ES modules. Use the new NodeNext option to easily interop between CommonJS and ES modules in the same project.
Full Lesson and Source Code https://fireship.io/lessons/typescript-nodejs-setup/