browserify / common-shakeify

browserify tree shaking plugin using `common-shake`
https://www.npmjs.com/package/common-shakeify
MIT License
105 stars 18 forks source link

Browserify + common-shakeify + Chart.js = infinite stack trace #52

Open ile opened 1 year ago

ile commented 1 year ago

I created this issue here: https://github.com/chartjs/Chart.js/issues/11479

Expected behavior

I'm using browserify@17.0.0 + common-shakeify@1.1.2 + chart.js@4.4.0.

In JavaScript I have this:

const Chart = require('chart.js/auto');

console.log('Hello');

Bundling will give me a stack trace and a crash.

Current behavior

ile@ilepc:~/src/sc2/browserify-chartjs$ ./run.sh 
/home/ile/src/sc2/browserify-chartjs/node_modules/escope/lib/scope.js:417
            var ref = new _reference2.default(node, this, assign || _reference2.default.READ, writeExpr, maybeImplicitGlobal, !!partial, !!init);
                      ^

RangeError: Maximum call stack size exceeded
    at ClassScope.__referencing (/home/ile/src/sc2/browserify-chartjs/node_modules/escope/lib/scope.js:417:23)
    at Referencer.Identifier (/home/ile/src/sc2/browserify-chartjs/node_modules/escope/lib/referencer.js:425:33)
    at Visitor.visit (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:104:34)
    at Visitor.visitChildren (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:88:26)
    at Visitor.visit (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:107:14)
    at Visitor.visitChildren (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:83:38)
    at Visitor.visit (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:107:14)
    at Visitor.visitChildren (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:88:26)
    at Visitor.visit (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:107:14)
    at Visitor.visitChildren (/home/ile/src/sc2/browserify-chartjs/node_modules/esrecurse/esrecurse.js:83:38)

Node.js v20.5.1

Reproducible sample

https://github.com/ile/browserify-chartjs

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v4.4.0

Browser name and version

No response

Link to your project

https://github.com/ile/browserify-chartjs

ile commented 1 year ago

The issue was es2022, which common-shakeify couldn't handle. It could handle es2021.

Here: https://github.com/chartjs/Chart.js/blob/master/rollup.config.js#L28