Closed paperdave closed 2 months ago
I'm assuming you are reporting just what I ran into.
Documentation states:
When deploying to production, we recommend the following:
bun build --compile --minify --sourcemap ./path/to/my/app.ts --outfile myapp
So I created test.ts
:
function main() {
throw new Error("test");
}
main();
and did the following:
$ bun test.ts
1 | function main() {
2 | throw new Error("test");
^
error: test
at main (/workspaces/dansdata/backend/test.ts:2:9)
at /workspaces/dansdata/backend/test.ts:5:1
Bun v1.1.21 (Linux x64)
$ bun build --compile --target=bun-linux-x64-modern --minify --sourcemap ./test.ts --outfile ./test
[4ms] minify
[1ms] bundle 1 modules
[78ms] compile ./test
$ ./test
2 | function n(){throw new Error("test")}n();
^
error: test
at n (/$bunfs/root/test:2:20)
at /$bunfs/root/test:2:39
Bun v1.1.21 (Linux x64)
As you can see, the stack trace is printed in minifed form from the executable which is unexpected.
i thought this was a regression from my recent changes but i can't find a version where this properly worked. on it
@paperdave I just verified this on 1.1.24 and while the stack trace is definitely better now, there's still something not working quite right:
test.ts
function recurse(n: number) {
if (n === 0) throw new Error("test");
else recurse(n - 1);
}
function main() {
recurse(5);
}
main();
Running the .ts file directly:
$ bun ./test.ts
1 | function recurse(n: number) {
2 | if (n === 0) throw new Error("test");
^
error: test
at recurse (/workspaces/dansdata/backend/test.ts:2:22)
at recurse (/workspaces/dansdata/backend/test.ts:3:8)
at recurse (/workspaces/dansdata/backend/test.ts:3:8)
at recurse (/workspaces/dansdata/backend/test.ts:3:8)
at recurse (/workspaces/dansdata/backend/test.ts:3:8)
at recurse (/workspaces/dansdata/backend/test.ts:3:8)
at main (/workspaces/dansdata/backend/test.ts:7:3)
at /workspaces/dansdata/backend/test.ts:10:1
Bun v1.1.24 (Linux x64)
Running on the compiled source file:
$ bun build --compile --target=bun-linux-x64-modern --minify --sourcemap ./test.ts --outfile ./test
[3ms] minify
[0ms] bundle 1 modules
[73ms] compile ./test
$ ./test
1 | function recurse(n: number) {
2 | if (n === 0) throw new Error("test");
^
error: test
at r (test.ts:2:22)
at r (test.ts:3:8)
at r (test.ts:3:8)
at r (test.ts:3:8)
at r (test.ts:3:8)
at r (test.ts:3:8)
at n (test.ts:7:3)
at test.ts:10:1
Bun v1.1.24 (Linux x64)
as you can see, the stack trace still uses the minifed function name (at r (...
) rather than the original name (at recurse (...
).
Reproduction from #12571, should still reproduce if instead of the genuine bundler error, you place a manual
throw new Error
into the code