#Trouble running the dev server with worker in dependency

9 messages · Page 1 of 1 (latest)

white plank
#

Hello,

I create a simple example of my workspace. It's default nuxt application with one dep. that build worker with vite.

When I build the app with:

  1. yarn # Install deps
  2. yarn workspace magic run build
  3. yarn dev

I succeed on every step. But when I start the dev server and load the default page that requires Worker from 'magic' package, I get an error.
I don't know why I get the content type of the request for worker.js as text/html;charset=utf-8.

Is there anything that I miss from the configuration of Nuxt or Vite in dep. for this to work?

Thank you for response.

torn eagleBOT
#

Hi @white plank. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm sorry, but the knowledge sources provided do not contain specific information about configuring Nuxt or Vite to support web workers bundled in dependencies, or about resolving issues where a worker file (like worker.js) is served with the wrong content type (text/html;charset=utf-8) in a Nuxt 3 development environment.

The available documentation covers general Vite and Nuxt configuration options, including how to pass Vite config directly via nuxt.config.ts and some details about Vite server options, but does not address web worker handling or related MIME type issues in the context of dependencies or monorepos. There are also no references to troubleshooting this specific scenario in the provided sources. If you need further help, you might consider reaching out to the Nuxt community or checking for related issues in the Nuxt GitHub repository.

If you have more specific configuration details or error logs, please provide them, and I can check if they match anything in the knowledge sources.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@white plank Kapa.ai is still learning and improving, please let me know how I did by reacting below.

viral rampart
#

Hey Makku,
The issue happens because the dev server can’t properly resolve the worker file path.
Instead of returning the JS file, it serves the Nuxt HTML fallback.

#

const worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });

#

try this

white plank
#

Yes this is working. Should I create issue that this is not working with ?worker import? 😄

viral rampart
#

Glad to hear, @white plank