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

Bug: Maximum call stack size exceeded #51

Closed
luislhl opened this issue Feb 25, 2021 · 23 comments · Fixed by #55
Closed

Bug: Maximum call stack size exceeded #51

luislhl opened this issue Feb 25, 2021 · 23 comments · Fixed by #55
Assignees
Labels
bug Something isn't working
Milestone

Comments

@luislhl
Copy link

luislhl commented Feb 25, 2021

Describe the bug
I'm getting this stack-trace when running the tool in my project

> typescript-coverage-report

RangeError: Maximum call stack size exceeded
    at getRootNames (/home/luislhl/Workspace/pareto/quantic-spa/node_modules/type-coverage-core/dist/tsconfig.js:148:15)
    at async Object.getProjectRootNamesAndCompilerOptions (/home/luislhl/Workspace/pareto/quantic-spa/node_modules/type-coverage-core/dist/tsconfig.js:18:23)
    at async Object.lint (/home/luislhl/Workspace/pareto/quantic-spa/node_modules/type-coverage-core/dist/core.js:17:44)

To Reproduce
Just running typescript-coverage-report without any extra options.

Expected behaviour
I expected the report to be generated

Environment

  • Tool version: 0.5.0
  • OS: Fedora Linux
  • Node version: v12.18.3
  • Npm version: 6.14.6

Additional context
Add any other context about the problem here.

@luislhl luislhl added the bug Something isn't working label Feb 25, 2021
@alexcanessa alexcanessa self-assigned this Feb 26, 2021
@alexcanessa
Copy link
Owner

Hmm I wonder how many files it's trying to run.

Interesting it would mean that we'd have to change the approach and have separate builds.

Could you try and run it with this:

--max-old-space-size=8192

@alexcanessa alexcanessa added help wanted Extra attention is needed and removed bug Something isn't working labels Mar 1, 2021
@sanjaypojo
Copy link

sanjaypojo commented Mar 31, 2021

Experiencing the same issue on a maxed out macbook pro.

--max-old-space-size=8192

Doesn't seem to recognize this flag. Output: unknown option '--max-old-space-size=8192'

EDIT: I tried running NODE_OPTIONS=--max-old-space-size=8192 typescript-coverage-report and get Maximum call stack size exceeded

@alexcanessa alexcanessa added bug Something isn't working and removed help wanted Extra attention is needed labels Mar 31, 2021
@alexcanessa
Copy link
Owner

@sanjaypojo could you try to run the package that validates the coverage (the one this package is built on) on your amount of files?

I'm trying to understand where the problem is.

https://github.com/plantain-00/type-coverage

@sanjaypojo
Copy link

sanjaypojo commented Mar 31, 2021

Hey @alexcanessa yes, I get the same error using type-coverage directly. The repo I'm running it on is pretty large (500+ files and 50+ dependencies)

@alexcanessa
Copy link
Owner

@sanjaypojo I've created an issue in that repo. I'll have a look myself too. Thanks for raising this.

@alexcanessa
Copy link
Owner

alexcanessa commented Mar 31, 2021

@all-contributors add @sanjaypojo for bugs

@allcontributors
Copy link
Contributor

@alexcanessa

I've put up a pull request to add @sanjaypojo! 🎉

@alexcanessa
Copy link
Owner

@all-contributors add @luislhl for bugs

@allcontributors
Copy link
Contributor

@alexcanessa

I've put up a pull request to add @luislhl! 🎉

@sanjaypojo
Copy link

Awesome @alexcanessa, happy to help with debugging / trying again any time!

@plantain-00
Copy link

If I add console.info(process.env.NODE_OPTIONS) in type-coverage js code, execute NODE_OPTIONS=--max-old-space-size=8192 type-coverage, I can get:

$ NODE_OPTIONS=--max-old-space-size=8192 type-coverage
--max-old-space-size=8192

So NODE_OPTIONS should works.
From the error stack, it seems caused by recursive function call, can you provide a minimal reproduce repo, or add some js code to debug which function and why it is recursive.

@plantain-00
Copy link

And it seems it errored when just finding tsconfig.json, so maybe just providing the tsconfig.json and it's extendsed tsconfig.json is enough to reproduce.

@luislhl
Copy link
Author

luislhl commented Apr 9, 2021

@plantain-00 , I tried debugging this.
The problem seems to be related to the glob lib used in this section of tsconfig.js:

function globAsync(pattern, ignore, cwd) {
    return new Promise((resolve, reject) => {
        console.log('globAsync', pattern, ignore, cwd);
        glob(pattern, { ignore, cwd }, (error, matches) => {
            console.log('glob callback');
            if (error) {
                reject(error);
            }
            else {
                resolve(matches);
            }
        });
    });
}

This glob callback is never printed. In the meantime, glob lib is stuck scanning/processing a lot of folders, including all folders inside node_modules.

The other console.log prints this line:

globAsync {/home/luislhl/Workspace/pareto/platform-spa/**/*.ts,/home/luislhl/Workspace/pareto/platform-spa/**/*.tsx,/home/luislhl/Workspace/pareto/platform-spa/**/*.js} [ 'node_modules', 'public', 'static' ] .

So it seems to be passing node_modules to be ignored, but glob isn't really ignoring it somehow.

Then, I modified the code to force passing an absolute path of node_modules, like this:

function globAsync(pattern, ignore, cwd) {
    return new Promise((resolve, reject) => {
        console.log('globAsync', pattern, ignore, cwd);
        glob(pattern, { ignore: ['/home/luislhl/Workspace/pareto/platform-spa/node_modules/**', 'public/**', 'static/**'], cwd }, (error, matches) => {
            console.log('glob callback')
            if (error) {
                reject(error);
            }
            else {
                resolve(matches);
            }
        });
    });
}

After this, the glob callback was called in no time at all.

So maybe it's just a question of adjusting the options passed to glob?

However, this still didn't solve all my problems, since I'm now getting an Out of Memory error.
But I still didn't debug this one, will try to do it when I have some more time.

P.S: I was running typescript-coverage-report to debug this, so I'm not sure yet if this memory problem would happen when running type-coverage directly.

<--- Last few GCs --->

[413331:0x59dc0c0]   133527 ms: Mark-sweep (reduce) 2041.1 (2050.8) -> 2040.1 (2052.1) MB, 2217.6 / 0.0 ms  (average mu = 0.129, current mu = 0.012) allocation failure scavenge might not succeed
[413331:0x59dc0c0]   135765 ms: Mark-sweep (reduce) 2041.2 (2051.1) -> 2040.1 (2052.1) MB, 2185.6 / 0.0 ms  (average mu = 0.077, current mu = 0.023) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xa04200 node::Abort() [node]
 2: 0x94e4e9 node::FatalError(char const*, char const*) [node]
 3: 0xb7978e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xb79b07 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xd34395  [node]
 6: 0xd34f1f  [node]
 7: 0xd42fab v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 8: 0xd46b6c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 9: 0xd1524b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
10: 0x105b23f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x1401219  [node]

@plantain-00
Copy link

type-coverage v2.17.1 should fix the glob issue.

@alexcanessa
Copy link
Owner

alexcanessa commented Apr 9, 2021

Ok I'll update type-coverage-core then and keep you posted.

@alexcanessa alexcanessa added this to the v0.5.1 milestone Apr 9, 2021
@alexcanessa
Copy link
Owner

This bug should be fixed in v0.5.1. @sanjaypojo are you able to test and see if it works?

@sanjaypojo
Copy link

Tested and works like a charm 💯 Thanks @alexcanessa 🙌🏽

@alexcanessa
Copy link
Owner

Thanks @plantain-00!

@harshmaur
Copy link

harshmaur commented Dec 23, 2021

I still get this issue.

RangeError: Maximum call stack size exceeded
    at getBaseConstraintOfType (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:53240:41)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:37)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)
    at getTypeFacts (/node_modules/typescript-coverage-report/node_modules/typescript/lib/typescript.js:62711:24)

Any ideas?

I am using it with a next.js project. It works fine on create react app project.

@alexcanessa
Copy link
Owner

@harshmaur and I believe you're using the latest version of the tool?

@harshmaur
Copy link

Yes. 0.6.1 actually.

@alexcanessa
Copy link
Owner

@harshmaur could you try with 0.6.2 please?

@titanium-cranium
Copy link

Getting this same error on 0.6.4

RangeError: Maximum call stack size exceeded
    at getRootNames (/<root path>/node_modules/type-coverage-core/dist/tsconfig.js:179:15)
    at async getProjectRootNamesAndCompilerOptions (/<path>/node_modules/type-coverage-core/dist/tsconfig.js:19:23)
    at async Object.lint (/<root path>/node_modules/type-coverage-core/dist/core.js:17:44)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants