WebWorker in AppRouter - document is not defined
Answered
Luke posted this in #help-forum
LukeOP
workerRef.current = new Worker(new URL("../worker.ts", import.meta.url));
this throws an error document is not defined
even inside a useEffect
It appears a worker path cannot be dynamic at all. Is there a way to create a static path to a webworker
.ts
file that will work in dev and prod?Answered by Luke
Resolved 👀
I believed this was an issue related to app vs page router, but the [page router example of using a web-worker](https://github.com/vercel/next.js/tree/canary/examples/with-web-worker) works just fine. Until, your page is built with an
Disabling the following:
This now works just fine.
I believed this was an issue related to app vs page router, but the [page router example of using a web-worker](https://github.com/vercel/next.js/tree/canary/examples/with-web-worker) works just fine. Until, your page is built with an
edge
runtime.Disabling the following:
export const runtime = "edge";
This now works just fine.
2 Replies
LukeOP
Resolved 👀
I believed this was an issue related to app vs page router, but the [page router example of using a web-worker](https://github.com/vercel/next.js/tree/canary/examples/with-web-worker) works just fine. Until, your page is built with an
Disabling the following:
This now works just fine.
I believed this was an issue related to app vs page router, but the [page router example of using a web-worker](https://github.com/vercel/next.js/tree/canary/examples/with-web-worker) works just fine. Until, your page is built with an
edge
runtime.Disabling the following:
export const runtime = "edge";
This now works just fine.
Answer
LukeOP
Possibly related https://github.com/vercel/next.js/issues/50539