webview-bun icon indicating copy to clipboard operation
webview-bun copied to clipboard

Bytecode compilation is not supported

Open baboon-king opened this issue 6 months ago • 2 comments

  1. run build script
bun build --compile --minify --sourcemap ./examples/basic.ts --outfile ./dist/basic --bytecode
  1. get error
Image

this why? https://bun.sh/docs/bundler/executables#bytecode-compilation

baboon-king avatar May 16 '25 02:05 baboon-king

From the bun docs, it's mentioned that bytecode compilation is experimental and only works with cjs. So if you somehow transpile this library to cjs, you could make it work.

Though there are no plans to support this right now, I'm keeping the issue open.

tr1ckydev avatar May 16 '25 04:05 tr1ckydev

I understand, you are correct. But there is no need to convert to cjs somehow, because when compiling with bytecode, the conversion is performed inside bun.

The core reasons for this are

  1. when bytecode is enabled, bun compiles the source code into cjs
  2. the use of the top-level-wait syntax in the source code is a hindrance.

So not using the top-level-wait syntax allows bytecode to work correctly.

It would be possible to rewrite the top-level-wait as an async function, but that would make the entire call chain asynchronous.

But the bytecode feature is experimental, so I agree with you to keep this issue

baboon-king avatar May 16 '25 05:05 baboon-king