tidalcycles / strudel

Web-based environment for live coding algorithmic patterns, incorporating a faithful port of TidalCycles to JavaScript
https://strudel.cc/
GNU Affero General Public License v3.0
579 stars 105 forks source link

Build error related to SharedWorker #1137

Open spitlo opened 2 days ago

spitlo commented 2 days ago

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.