Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded (Infinite Loop) at computeUsagesRecursively #314

Closed
KieranTH opened this issue Apr 14, 2024 · 5 comments
Closed
Assignees
Labels
Milestone

Comments

@KieranTH
Copy link

KieranTH commented Apr 14, 2024

Bug report
Computing usages recursively causes infinite loop when type declarations are cyclic.

After spending a few hours attempting to debug this myself in the types-usage-evaluator file, I've had no luck.

I personally have valid cyclic types in a GQL backend I'm running, but I've also been able to replicate the issue with another more popular package: React FontAwesome.

I'm not entirely familiar with how other tools such as TSC deal with this issue, my first instinct is to run a check on whether a Type/Interface contains itself at any other point in the tree and exit the loop, but unsure if that's the correct approach.

Here's a repo that displays this issue in a very simple setup:

https://github.com/KieranTH/DTS-Bundle-Circular-Issue

I'm using Bun in this example but any runtime/package manager should have this issue.

To reproduce the issue just clone that repo and run bun i && bun run build.mjs

Thanks!

Actual output

RangeError: Maximum call stack size exceeded.
      at computeUsagesRecursively (/home/project/node_modules/dts-bundle-generator/dist/types-usage-evaluator.js:155:13)
      at computeUsageForNode (/home/project/node_modules/dts-bundle-generator/dist/types-usage-evaluator.js:55:21)
      at visitNodes (/home/project/node_modules/typescript/lib/typescript.js:27934:24)
      at forEachChildInSourceFile (/home/project/node_modules/typescript/lib/typescript.js:28556:18)
      at forEachChild (/home/project/node_modules/typescript/lib/typescript.js:28019:37)
      at computeUsages (/home/project/node_modules/dts-bundle-generator/dist/types-usage-evaluator.js:40:13)
      at new TypesUsageEvaluator (/home/project/node_modules/dts-bundle-generator/dist/types-usage-evaluator.js:10:9)
      at generateDtsBundle (/home/project/node_modules/dts-bundle-generator/dist/bundle-generator.js:21:33)
@timocov
Copy link
Owner

timocov commented Apr 14, 2024

but any runtime/package manager should have this issue.

Apparently, if you just run dts-bundle-generator tool it works just fine:

$ ./node_modules/.bin/dts-bundle-generator index.ts
Compiling input files...
Processing index.ts
Writing index.ts -> index.d.ts
Checking generated files...
Done in 1.31s

$ cat index.d.ts
// Generated by dts-bundle-generator v9.3.1

import { faCat, faSquareMinus } from '@fortawesome/free-solid-svg-icons';

export {
        faCat,
        faSquareMinus,
};

export {};

I'm curious what bun-plugin-dts adds to the config so it makes it to fail...

@timocov
Copy link
Owner

timocov commented Apr 14, 2024

It seems it might be the issue with Bun itself. Well, technically it is just the difference between runtimes. Apparently nodejs has higher limits for the callstack size than bun, thus you see this error.
I just cut a ticket to bun oven-sh/bun#10270 just in case if they want to sync/increase this value, but regardless I'll try to fix it from my size because even if they will do that, there is a cache to hit this issue even with a higher limit with more complex types.

@timocov timocov self-assigned this Apr 14, 2024
@timocov timocov added the Bug label Apr 14, 2024
@timocov timocov added this to the 9.4 milestone Apr 14, 2024
@timocov
Copy link
Owner

timocov commented Apr 14, 2024

Oh btw this has been fixed in #303 already (but it is not published yet). I just validated with local build it works just fine.

@timocov timocov closed this as completed Apr 14, 2024
@KieranTH
Copy link
Author

Appreciate the quick response!

Thank you for looking into it and creating the issue on Bun's side!

I'll keep a look out for the performance improvement release :) Thanks

@timocov
Copy link
Owner

timocov commented Apr 15, 2024

The fix has been published in 9.4.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants