modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.23k stars 297 forks source link

[web-dev-server] Problems with Deno #2843

Open stefanfrede opened 1 week ago

stefanfrede commented 1 week ago

Hello,

I am trying to get WDS to work in a Deno 2 environment, but no luck so far.

This is my project structure:

.
├── deno.json
├── deno.lock
├── public
│   ├── index.html
│   ├── index.css
│   ├── index.js
│   └── …
└── …

And this is what I did:

I installed the server:

deno add --dev npm:@web/dev-server

Added some tasks to my deno.json file:

{
    "tasks": {
        "start": "deno run -A npm:@web/dev-server --root-dir public/ --node-resolve",
        "start:watch": "deno run -A npm:@web/dev-server --root-dir public/ --node-resolve --watch"
    },
    "nodeModulesDir": "auto",
    "imports": {
        "@web/dev-server": "npm:@web/dev-server@^0.4.6"
    }
}

And started the server:

deno task start:watch

Task start:watch deno run -A npm:@web/dev-server --root-dir public/ --watch
Web Dev Server started...

    Root dir: <project path>/public
    Local:    http://localhost:8000/
    Network:  http://100.85.0.1:8000/

When I now open http://localhost:8000/ in my browser I get a blank page and the following errors in my console:

The stylesheet http://localhost:8000/index.css was not loaded because its MIME type, “text/plain”, is not “text/css”.

Loading module from “http://localhost:8000/index.js” was blocked because of a disallowed MIME type (“text/plain”).

Loading module from “http://localhost:8000/__web-dev-server__web-socket.js” was blocked because of a disallowed MIME type (“text/plain”).

I can see that my `index.html' has been loaded, but I suspect that nothing is being displayed due to MIME type errors.

What am I missing?

Thanks in advance!

Maybe it helps to clarify things: https://codeberg.org/stefanfrede/frede-dev/src/branch/refactor/switch-to-wds.