Closed laurensV closed 3 weeks ago
I got the same issue, with the puppeteer
package.
Observing the same incorrect behavior when trying to build code importing the jspdf
package.
Upon further testing, at least for the jspdf
package, it appears the issue arises when build with bun build [...] --target=bun
. When using bun build [...] --target=node
, it works fine, even when the bundled code is executed with bun.
After more testing, the bundle built with --target=node
starts without errors, but it still errors at runtime when constructing the same class that causes parsing issues on startup when bundled with --target=bun
.
Same problem without our CLI tools here: https://github.com/sprucelabsai-community/spruce-cli-workspace
cd packages/spruce-cli
bun build ./src/index.ts --compile --outfile=spruce
./spruce
Experiencing same issue
❯ bun -v
1.1.10
bun build ./index.js --compile --outfile mycli
❯ ./mycli
45513 | this._process();
45514 | return this._hash;
45515 | }
45516 | }
45517 |
45518 | class _Readable extends EventEmitter2 {
^
TypeError: The superclass is not a constructor.
at /$bunfs/root/mycli:45518:1
I got the same issue when using jsx-email
(https://github.com/shellscape/jsx-email/issues/197)
Here is a minimal reproduction example https://github.com/nephix/jsx-email-repro (bun 1.1.12
)
It works fine with
bun run index.ts
but fails with
bun run build
bun dist/index.js
│ 132468 |
│ 132469 | class Registry2 extends Registry$1 {
│ ^
│ TypeError: The superclass is not a constructor.
│ at /Users/nephix/Projects/boilerplate/apps/backend/dist/index.js:132469:1
│ note: missing sourcemaps for /Users/nephix/Projects/boilerplate/apps/backend/dist/index.js
│ note: consider bundling with '--sourcemap' to get an unminified traces
│
│ Bun v1.1.12 (macOS arm64)
│ error: script "start" exited with code 1
Encountered the same issue with W3CBaggagePropagator
when using @sentry/bun
Bun version: v1.1.20
await Bun.build({
entrypoints: ['src/main.ts'],
outdir: 'dist',
target: 'bun',
sourcemap: 'external',
})
Btw, this probably happened when I added this:
import('reflect-metadata').then(() => {
import('./server')
})
(The server
file contains all the rest of the code, including @sentry/bun
imports)
Same issue with llamaindex
when using OpenAI
.
import { OpenAI } from "llamaindex";
const openaiLLM = new OpenAI({ model: "gpt-4o-mini", temperature: 0.7 });
This was fixed in Bun v1.1.21. To get Bun v1.1.21, please run
bun upgrade
If you're still running into this issue, please leave a comment , we'll re-open it and @paperdave will investigate
What version of Bun is running?
1.0.26+c75e768a6
What platform is your computer?
Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
Some packages run just fine when using bun directly, but when trying to use
bun build
it gives this errorTypeError: The superclass is not a constructor.
I created a small example repo: First install the package, for example
@solana/web3.js
create file
index.js
that uses the package:Running this file directly with
bun index.js
works fine, but when trying to build first and then run it (or when using--compile
flag to put it into one executable), it fails:Seen this behaviour in multiple packages now, like puppeteer (https://github.com/oven-sh/bun/issues/6261) and AWS CDK (https://github.com/oven-sh/bun/issues/3088)
You can find the example repo code here: https://github.com/laurensV/bun-build-bug-solana-web3js
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response