You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// @ts-expect-errorimportworkerTargetfrom"~/worker/worker-target.worker"with{type: "file"};// this is basically so Bun includes the file in the bundling process
...
newWorker(URL.createObjectUURL(Bun.file(workerTarget)));
...
worker-target.worker.ts
...
import{db}from"~/db/database";
...
all that works fine during dev (basically just bun run src/index.ts), and even builds fine, whether using
bun build --target bun --outdir ./dst src/index.ts
or
bun build --compile --target bun-linux-x64 --outfile dst/server src/index.ts
but when you try to run the built/bundled program either with
# inside dst directory, with node_modules directory present
bun run index.js
or
./server
I got an error Cannot find module '~/database' from 'blob:####' or something along those lines, which i guess makes sense because i guess worker files here are treated as an asset and the "reference" of the import is not solved.
And I feel like I am doing something very wrong, now the question is, is there any way or perhaps proper way to use Worker with build --compile or do i stuck just shipped the "raw source code" so the worker could function (because even doing bun build --target bun --outdir ./dst src/index.ts also doesn't work)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
So I don't know if this is Bun's bug, limitation, or user error and skill issue (most likely), so I put this here instead.
I have a project with setup like this
with tsconfig like this
{ "compilerOptions": { ... "paths": { "~/*": [ "src/*" ] } } }worker-loader.tsworker-target.worker.tsall that works fine during dev (basically just
bun run src/index.ts), and even builds fine, whether usingor
but when you try to run the built/bundled program either with
# inside dst directory, with node_modules directory present bun run index.jsor
I got an error
Cannot find module '~/database' from 'blob:####'or something along those lines, which i guess makes sense because i guess worker files here are treated as an asset and the "reference" of the import is not solved.And I feel like I am doing something very wrong, now the question is, is there any way or perhaps proper way to use Worker with
build --compileor do i stuck just shipped the "raw source code" so the worker could function (because even doingbun build --target bun --outdir ./dst src/index.tsalso doesn't work)Beta Was this translation helpful? Give feedback.
All reactions