mathe42 / vite-plugin-comlink

Use WebWorkers in Vite with comlink!
MIT License
170 stars 18 forks source link

Getting an error saying : Expected a JavaScript module script but the server responded with a MIME type of "text/html" #136

Closed litcodeur closed 4 months ago

litcodeur commented 5 months ago

When I'm trying to use this plugin to work with webworkers, I'm getting the following error message in my browser console.

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Screenshot 2024-04-27 at 4 16 46 PM

And when I look into the path that it tries to fetch manually by opening it in a new tab, it returns a not found but the type of content returned by server is of html.

Lmk if there's more info I can provide to help out with the issue, Thanks!

litcodeur commented 5 months ago

I think, this might be a bug. When named my worker file foo.worker.ts, it failed with the above error message, but when I renamed it to fooworker.ts (without a dot separator) it worked as expected.

mathe42 commented 5 months ago

Please provide Code for a reproduction. And what Browser etc. you use.

Does this only happen in dev Mode or also production?

Also this might be an upstream issue in vite.

litcodeur commented 5 months ago

Here's a codesandbox with a minimal reproduction: https://codesandbox.io/p/devbox/charming-albattani-ktmypy

I'm using Arc browser (chromium based), on Mac device (M series).

Haven't built and pushed changes to verify, but can confirm happens in dev mode.

mathe42 commented 5 months ago

Workaround:

new URL("./worker.fail.ts", import.meta.url)

include extension in url.

I'm currently evaluating if this is a problem with this plugin or upstream in vite.

mathe42 commented 4 months ago

fixed with v5.0.0

litcodeur commented 4 months ago

Thanks!