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
Uncaught TypeError: Cannot convert undefined to a BigInt
at BigInt ()
at <instance_members_initializer> (editor.bun.js:32744:9)
at new FocusedElement (editor.bun.js:32745:14)
at <static_initializer> (editor.bun.js:32743:17)
Additional information
esbuild can bundle this but bun't
class FocusedElement {
public readonly key = (BigInt(this.byte) << 1n) | (this.char ? 1n : 0n);
constructor(
public readonly char: boolean,
public readonly byte: number,
) {}
}
Reproduced with {"compilerOptions":{"target":"ES2020"}} in tsconfig.json: bun a.ts throws where tsc and esbuild print 11n. Bun ignores target when it picks the useDefineForClassFields default.
Fix drafted in #47401. It waits for a maintainer decision on whether target should imply that default (see the question below).
This needs a maintainer decision before the fix can land. @Jarred-Sumner
The report reduces to this: Bun reads only an explicit useDefineForClassFields from tsconfig.json. tsc and esbuild also derive its default from target: false below ES2022, true from ES2022 on. With {"compilerOptions":{"target":"ES2020"}} and no flag, tsc 6.0.2 and esbuild 0.21.5 print 11n for the class in this report. Bun throws. Without a tsconfig, or with target at ES2022 or above, all three throw, so that case is not a bug.
#47401 (a port of #40924) makes Bun derive the default from target in the transpiler, the bundler, Bun.Transpiler and the AOT checker. Two things in the repo say the current behavior is deliberate:
The checker query fixture diagnostic-class/old-target-class-fields in test/aot/checker-queries/call-target.programs says: "bun run leaves class fields where they are written unless useDefineForClassFields is false, and a default value in front of the body, whatever the target. No rule about where tsc would move them counts."
The question: should a target below ES2022 with no explicit flag imply [[Set]] class fields, as tsc and esbuild do? If yes, #47401 is ready for review. If no, I will close it, and the workaround is "useDefineForClassFields": false in compilerOptions.
One cost of "yes": with [[Set]] semantics Bun inserts the field assignments after the first top-level super() statement. A constructor whose super() is inside if/else then throws ReferenceError at new. That gap exists today with the explicit flag. tsc rejects that shape with TS2376, esbuild wraps the nested super() calls. A target below ES2022 is far more common than the explicit flag, so "yes" should close that gap in the same change.
Activity
robobun commentedon Oct 29, 2026
Reproduced with
{"compilerOptions":{"target":"ES2020"}}in tsconfig.json:bun a.tsthrows where tsc and esbuild print11n. Bun ignorestargetwhen it picks theuseDefineForClassFieldsdefault.Fix drafted in #47401. It waits for a maintainer decision on whether
targetshould imply that default (see the question below).robobun commentedon Oct 29, 2026
This needs a maintainer decision before the fix can land. @Jarred-Sumner
The report reduces to this: Bun reads only an explicit
useDefineForClassFieldsfrom tsconfig.json. tsc and esbuild also derive its default fromtarget:falsebelow ES2022,truefrom ES2022 on. With{"compilerOptions":{"target":"ES2020"}}and no flag, tsc 6.0.2 and esbuild 0.21.5 print11nfor the class in this report. Bun throws. Without a tsconfig, or withtargetat ES2022 or above, all three throw, so that case is not a bug.#47401 (a port of #40924) makes Bun derive the default from
targetin the transpiler, the bundler,Bun.Transpilerand the AOT checker. Two things in the repo say the current behavior is deliberate:src/sema/driver/compile/tests/governing_projects.rshas the testclass_fields_stay_where_they_are_written_whatever_the_target, andsrc/sema/config/build_options.rsreplaces tsc's target rule with "explicitfalseonly" (Compile TypeScript to machine code ahead of time:bun build --compile --aot#45631).diagnostic-class/old-target-class-fieldsintest/aot/checker-queries/call-target.programssays: "bun runleaves class fields where they are written unlessuseDefineForClassFieldsis false, and a default value in front of the body, whatever the target. No rule about where tsc would move them counts."bun build --compile --aot#45631 said "As everywhere in Bun,targetandverbatimModuleSyntaxdon't change the code." (AOT: fixes for modules, classes and Workers, WebKit upgrade, shorter compiler docs #47129 removed that sentence when it shortened the docs.)The question: should a
targetbelow ES2022 with no explicit flag imply[[Set]]class fields, as tsc and esbuild do? If yes, #47401 is ready for review. If no, I will close it, and the workaround is"useDefineForClassFields": falseincompilerOptions.One cost of "yes": with
[[Set]]semantics Bun inserts the field assignments after the first top-levelsuper()statement. A constructor whosesuper()is insideif/elsethen throwsReferenceErroratnew. That gap exists today with the explicit flag. tsc rejects that shape with TS2376, esbuild wraps the nestedsuper()calls. Atargetbelow ES2022 is far more common than the explicit flag, so "yes" should close that gap in the same change.