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

Worker path resolution inconsistency between dev and build modes #15981

Open
kmate19 opened this issue Dec 24, 2024 · 0 comments
Open

Worker path resolution inconsistency between dev and build modes #15981

kmate19 opened this issue Dec 24, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@kmate19
Copy link

kmate19 commented Dec 24, 2024

What version of Bun is running?

1.1.42+50eec0025

What platform is your computer?

Linux 5.15.153.1-microsoft-standard-WSL2 x86_64 unknown

What steps can reproduce the bug?

Here’s a minimal reproduction of the issue:

Create a src/index.ts file:

console.log("Starting app...");

new Worker(new URL("./workers/worker.ts", import.meta.url).href);

Create a src/workers/worker.ts file:

console.log("Hello from the worker!");

Run the following commands:
Development Mode:

bun run ./src/index.ts --watch

Build Mode:

bun build --sourcemap --minify --compile --outfile ./dist/output --target bun ./src/index.ts ./src/workers/worker.ts
./dist/output

What is the expected behavior?

According to the Bun documentation, any of the following should work for worker paths, consistently across both dev and build modes:

new Worker("./workers/emailWorker.ts");
new Worker(new URL("./workers/emailWorker.ts", import.meta.url));
new Worker(new URL("./workers/emailWorker.ts", import.meta.url).href);

The worker file should resolve correctly and execute without errors in both modes.

What do you see instead?

Development Mode:
Running bun run ./src/index.ts --watch produces the following:

Hello from the worker!

Running

bun build --sourcemap --minify --compile --outfile ./dist/output --target bun ./src/index.ts ./src/workers/worker.ts
./dist/output

gives the following:

1 | new Worker(new URL("./workers/worker.ts", import.meta.url).href);
    ^
TypeError: BuildMessage: ModuleNotFound resolving "/$bunfs/root/workers/worker.ts" (entry point)
      at src/index.ts:1:1

Bun v1.1.42 (Linux x64)

Additional information

Would love clarification on whether this is a bug or intended behavior. Thank you!

@kmate19 kmate19 added bug Something isn't working needs triage labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant