Next.js Discord

Discord Forum

new WebWorker + assetPrefix = 🤯

Unanswered
American posted this in #help-forum
Open in Discord
AmericanOP
Hello!

I'm trying to load a webworker, like this:
workerRef.current = new Worker(
  new URL("../../transformers/transformers.worker.ts", import.meta.url),
);


I'm also using an assetPrefix. I get this error:

SyntaxError: WorkerGlobalScope.importScripts: Failed to load worker script at "http://localhost:3000http://localhost:3030/_next/static/chunks/66c92_onnxruntime-web_dist_33c4af75._.js" e43b0848-5ae9-40d0-ad50-89a8ed94ce83:11:14


http://localhost:3000 = dev server
http://localhost:3030 = asset prefix

7 Replies

European Turtle-Dove
This happens because when u use assetPrefix, the Worker URL gets resolved incorrectly your code is prepending the dev server URL and the assetPrefix resulting in a malformed double URL
AmericanOP
Yes, so is it a bug?
@American Yes, so is it a bug?
European Turtle-Dove
@American DM me
@European Turtle-Dove <@131748314256244736> DM me
AmericanOP
Why not take it here? So other people can find the solution too
please use the public/ folder for the worker and load it with the asset prefix
or remove assetPrefix in dev in next.config.js