Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error related to SharedWorker #1137

Open
spitlo opened this issue Jun 26, 2024 · 0 comments
Open

Build error related to SharedWorker #1137

spitlo opened this issue Jun 26, 2024 · 0 comments

Comments

@spitlo
Copy link

spitlo commented Jun 26, 2024

When building my local project, as well as when building the examples in this repo, a build error occurs. The clockworker.js script is not found.

I’ve checked the Vite docs, and I think the error occurs because of how the import statement is written in neocyclist.js.

If I re-write is as described in the Vite docs, the build command runs without errors:

import { logger } from './logger.mjs';

+import SharedWorker from './clockworker.js?sharedworker'

export class NeoCyclist {
  constructor({ onTrigger, onToggle, getTime }) {
    this.started = false;
    this.cps = 0.5;
    this.lastTick = 0; // absolute time when last tick (clock callback) happened
    this.getTime = getTime; // get absolute time
    this.time_at_last_tick_message = 0;

    this.num_cycles_at_cps_change = 0;
    this.onToggle = onToggle;
    this.latency = 0.1; // fixed trigger time offset
    this.cycle = 0;
    this.id = Math.round(Date.now() * Math.random());
    this.worker_time_dif;
-   this.worker = new SharedWorker(new URL('./clockworker.js', import.meta.url));
+   this.worker = new SharedWorker()
    this.worker.port.start();

NB: I have not been able to confirm that the worker still works with this solution, only that the build command succeeds, and that I get sound.

I have created a minimal reproducible example here:
https://github.com/spitlo/strudel-web-build-error-mre/

Install dependencies and run the build command (I use yarn build) to see the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant