Laterneman
Laterneman

Reputation: 297

Cannot import WebWorker file in Vue 3 app

I would like to use Comlink in my Vue 3 application and I think Comlink just works fine however when I try to reference my worker for new Worker() I think it fails to take hold onto that file. My tree looks like this: src --pages ----page.vue --workers ----worker.js

My worker.js:

import * as Comlink from 'comlink';

const worker = {
  trial() {
    return 'hello';
  },
};

Comlink.expose(worker);

My page.vue:

import * as Comlink from "comlink";

export default {
  methods: {
    tryOnClick() {
      const worker = new Worker("../../workers/worker.js");
      Comlink.wrap(worker);
      worker.trial();
    },
  },
};

(Later I would use my worker in a manager class and not directly in the page I just want to try it out) This gives me the error in the console:

worker.js:1 Uncaught SyntaxError: Unexpected token '<'

When I open this error up it seems like it fails at the very beginning of the HTML:

<!DOCTYPE html>

How should I reference my worker.js when I initialize the new Worker?

Upvotes: 0

Views: 532

Answers (0)

Related Questions