npm run dev to boot up the app. You should see a runtime exception. If you go to src/playground/worker-struct.ts you can comment out c and e in the workers object to see it "working" without the runtime exceptions.
Current vs. Expected behavior
const path = new URL("./workers/a", import.meta.url);
const file = "a";
const workers = {
// Works
a: new Worker(new URL("./workers/a", import.meta.url), {
type: "module",
name: "worker struct > a",
}),
// Nextjs treats as static file, does not work
b: new Worker(path, {
type: "module",
name: "worker struct > b",
}),
// Runtime exception
c: new Worker(new URL(`./workers/${file}`, import.meta.url), {
type: "module",
name: "worker struct > c",
}),
// Works
d: new Worker(new URL(`./workers/${"a"}`, import.meta.url), {
type: "module",
name: "worker struct > d",
}),
// Runtime exception
e: getWorker("test", "a"),
};
I would expect at a bare minimum a, c, d, and e to work but would also like additional clarification on b regarding fully dynamic path values.
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This is really more of a general "how should this work?" type of question / bug report but given there may actually be a bug hidden in here I decided to open an issue vs. a discussion thread. Some backstory, my team is working on some abstractions around web workers and we were running into some oddities around how Next (or Webpack presumably) handles certain scenarios. Included in the code to reproduce the issue are five scenarios.
src/playground/worker-struct.ts
I have deduced that b is likely due to the note here regarding using fully dynamic values for import statements. The really odd one is c vs. d since those have a partially static path with c having a dynamic value.
⚠️ Additional note, none of the example seem to work with next --turbo
Link to the code that reproduces this issue
https://github.com/brandonjpierce/nextjs-workers
To Reproduce
npm run dev
to boot up the app. You should see a runtime exception. If you go tosrc/playground/worker-struct.ts
you can comment outc
ande
in theworkers
object to see it "working" without the runtime exceptions.Current vs. Expected behavior
I would expect at a bare minimum
a
,c
,d
, ande
to work but would also like additional clarification onb
regarding fully dynamic path values.Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This is really more of a general "how should this work?" type of question / bug report but given there may actually be a bug hidden in here I decided to open an issue vs. a discussion thread. Some backstory, my team is working on some abstractions around web workers and we were running into some oddities around how Next (or Webpack presumably) handles certain scenarios. Included in the code to reproduce the issue are five scenarios.
src/playground/worker-struct.ts
I have deduced that
b
is likely due to the note here regarding using fully dynamic values for import statements. The really odd one isc
vs.d
since those have a partially static path withc
having a dynamic value.⚠️ Additional note, none of the example seem to work with
next --turbo