oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.31k stars 2.78k forks source link

Function conflict using `bun build` together with Chart.JS #14110

Open sajoku opened 1 month ago

sajoku commented 1 month ago

What version of Bun is running?

1.1.29+6d43b3662

What platform is your computer?

Darwin 24.0.0 arm64 arm

What steps can reproduce the bug?

When creating a Chart from Chart.js it will get into a recursive error. Uncaught RangeError: Maximum call stack size exceeded

index.js:2120 Uncaught RangeError: Maximum call stack size exceeded
    at getComputedStyle (index.js:2120:45)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)
    at getComputedStyle (index.js:2120:71)

It looks like the getComputedStyle is the culprit. A workaround is using --minify-syntax to "alias" the functions. I am not sure if this is something Bun should fix or if I should knock on Chart.js' door 🙂

What is the expected behavior?

I would expect no clashes on function names when running Bun build. Or getting warned when there are clashes.

What do you see instead?

Uncaught RangeError: Maximum call stack size exceeded

Additional information

I created a reproducible project over here https://github.com/sajoku/chartjs-bun/tree/main.

paperdave commented 1 month ago

this reminds me of an issue that renamed a function incorrectly, causing infinite recursion. could not find it. i suspect that is happening here.

note that my assignment currently means it is my responsibility to fix it, but i am spending most of my time on #14025 (afterwards, i'll do a small pass and get some bundler bugs fixed)

sajoku commented 1 month ago

this reminds me of an issue that renamed a function incorrectly, causing infinite recursion. could not find it. i suspect that is happening here.

note that my assignment currently means it is my responsibility to fix it, but i am spending most of my time on #14025 (afterwards, i'll do a small pass and get some bundler bugs fixed)

The workaround is good enough for me at the moment.

That renaming happens from bun's internals I take it? Could I try to pin point that myself to help in with finding the exact problem?

sirenkovladd commented 1 month ago

yes, this is a problem with the function name being the same as the global value

this patch helps to fix that as well

diff --git a/dist/chunks/helpers.segment.js b/dist/chunks/helpers.segment.js
index f38b565a20f3e4c27fb91bde2daec9155754ee43..3543790f84f55bda90f7f0ba0e1037af06a30ea1 100644
--- a/dist/chunks/helpers.segment.js
+++ b/dist/chunks/helpers.segment.js
@@ -2164,3 +2164,3 @@
 }
-const getComputedStyle = (element)=>element.ownerDocument.defaultView.getComputedStyle(element, null);
+const _remove = ()=>{};
 function getStyle(el, property) {