Skip to content

Compiler takes a long time, then throws: "RangeError: Value undefined out of range for undefined options property undefined" #44796

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

Closed
panta82 opened this issue Jun 28, 2021 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fixed A PR has been merged for this issue

Comments

@panta82
Copy link

panta82 commented Jun 28, 2021

Bug Report

🔎 Search Terms

"RangeError", "Value undefined out of range for undefined options property undefined"

🕗 Version & Regression Information

Compiler language server slows down to a crawl and stops giving answers.

tsc command line utility crashes with the following stack trace:

/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90672
                throw e;
                ^

RangeError: Value undefined out of range for undefined options property undefined
    at Map.set (<anonymous>)
    at recursiveTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50949:30)
    at isRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50530:34)
    at checkTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50216:26)
    at isTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50179:24)
    at isTypeSubtypeOf (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49467:20)
    at /home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47274:90
    at Object.some (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:658:25)
    at _loop_14 (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47274:45)
    at removeStringLiteralsMatchedByTemplateLiterals (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47279:21)

This started happening when I went perhaps a bit overboard with generics.

It showed up in 4.3.4. I went back to 4.2.x and it's still there.

Node version: v14.17.0

⏯ Playground Link

Sorry, this happens in a complicated project, I don't know how to extract it.

💻 Code

See above

🙁 Actual behavior

Compiler slows down and crashes during build.

🙂 Expected behavior

Compiler can deal with my fancy generics :)


I know this is not a lot to go on. I am primarily curious what should I do now?

Is this the normal behavior of tsc? Eg. if you push it too hard, it crashes? And I should just remove some of the generics and move on?

Or is this a genuine bug. And the compiler either shouldn't have stalled, or there should have been some mechanism where it aborts compilation with "things are too complex" error message?

If the latter is the case, I am open to trying to extract the situation into some kind of mini project or reproducible use case.

Thanks.

@panta82
Copy link
Author

panta82 commented Jun 28, 2021

Here is the entire stack trace.

$ NODE_OPTIONS=--stack-trace-limit=1000 node_modules/.bin/tsc --project ./tsconfig.json --noEmit
/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90672
                throw e;
                ^

RangeError: Value undefined out of range for undefined options property undefined
    at Map.set (<anonymous>)
    at recursiveTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50949:30)
    at isRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50530:34)
    at checkTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50216:26)
    at isTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50179:24)
    at isTypeSubtypeOf (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49467:20)
    at /home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47274:90
    at Object.some (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:658:25)
    at _loop_14 (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47274:45)
    at removeStringLiteralsMatchedByTemplateLiterals (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47279:21)
    at getUnionType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:47323:21)
    at mapType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:54514:45)
    at mapTypeWithAlias (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:54519:17)
    at instantiateConditionalType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49255:28)
    at getConditionalTypeInstantiation (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49243:30)
    at getConstraintOfDistributiveConditionalType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45324:40)
    at getConstraintFromConditionalType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45333:20)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45472:38)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45435:40)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45435:40)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45435:40)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getResolvedBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45390:74)
    at getBaseConstraintOfType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45374:34)
    at getApparentType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45528:46)
    at getReducedApparentType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45542:35)
    at getPropertiesOfType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45248:20)
    at getPropertiesOfUnionOrIntersectionType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45230:43)
    at getReducedType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45703:34)
    at getNormalizedType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50190:48)
    at isRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50470:30)
    at checkTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50216:26)
    at isTypeRelatedTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:50179:24)
    at isTypeAssignableTo (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49470:20)
    at instantiateTypeWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49336:42)
    at instantiateTypeWithAlias (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49275:26)
    at instantiateType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49261:37)
    at getMappedType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:48985:63)
    at /home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49238:92
    at Object.map (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:371:29)
    at getConditionalTypeInstantiation (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49238:40)
    at instantiateTypeWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49327:24)
    at instantiateTypeWithAlias (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49275:26)
    at instantiateType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:49261:37)
    at getTrueTypeFromConditionalType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:48408:70)
    at getSimplifiedConditionalType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:48214:28)
    at getSimplifiedType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:48161:41)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:56)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45435:40)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45435:40)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45435:40)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45419:25)
    at computeBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45473:42)
    at getImmediateBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45399:34)
    at getResolvedBaseConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45390:74)
    at getBaseConstraintOfType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45374:34)
    at getBaseConstraintOrType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:45380:20)
    at isGenericTypeWithUnionConstraint (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:55752:49)
    at someType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:54456:68)
    at getNarrowableTypeForReference (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:55765:17)
    at checkIdentifier (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:55881:20)
    at checkExpressionWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62473:28)
    at checkExpression (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62428:38)
    at checkJsxExpression (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:57919:28)
    at checkExpressionWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62554:28)
    at checkExpression (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62428:38)
    at checkExpressionForMutableLocation (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62229:24)
    at checkJsxAttribute (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:57506:19)
    at createJsxAttributesTypeFromAttributesProperty (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:57523:36)
    at checkJsxAttributes (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:57630:20)
    at checkExpressionWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62562:28)
    at checkExpression (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62428:38)
    at checkExpressionWithContextualType (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:62132:28)
    at checkApplicableSignatureForJsxOpeningLikeElement (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:58963:34)
    at getSignatureApplicabilityError (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:59044:22)
    at chooseOverload (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:59516:25)
    at resolveCall (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:59360:26)
    at resolveJsxOpeningLikeElement (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:60014:20)
    at resolveSignature (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:60035:28)
    at getResolvedSignature (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:60046:26)
    at checkJsxOpeningLikeElementOrOpeningFragment (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:57885:27)
    at checkJsxSelfClosingElementDeferred (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:57466:13)
    at checkDeferredNode (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:67123:21)
    at Map.forEach (<anonymous>)
    at checkDeferredNodes (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:67093:37)
    at checkSourceFileWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:67168:17)
    at checkSourceFile (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:67135:13)
    at getDiagnosticsWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:67216:17)
    at Object.getDiagnostics (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:67205:24)
    at /home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90693:85
    at runWithCancellationToken (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90665:24)
    at getBindAndCheckDiagnosticsForFileNoCache (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90682:20)
    at getAndCacheDiagnostics (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90930:26)
    at getBindAndCheckDiagnosticsForFile (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90679:20)
    at getSemanticDiagnosticsForFile (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90676:60)
    at /home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90616:24
    at Object.flatMap (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:424:25)
    at getDiagnosticsHelper (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90612:56)
    at Object.getSemanticDiagnostics (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:90623:20)
    at emitFilesAndReportErrors (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:94956:57)
    at Object.emitFilesAndReportErrorsAndGetExitStatus (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:94985:18)
    at performCompilation (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:97601:29)
    at executeCommandLineWorker (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:97485:17)
    at Object.executeCommandLine (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:97530:20)
    at Object.<anonymous> (/home/panta/dev/project/webui/node_modules/typescript/lib/tsc.js:97818:4)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/panta/dev/project/webui/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

@andrewbranch
Copy link
Member

Is this the normal behavior of tsc? Eg. if you push it too hard, it crashes?

No. The compiler should never crash. I’m assuming you can’t share the project that causes this? Any additional info you could share, or if you can manage to create a contained reproduction, would be super helpful. I’m not sure there’s anything we can do with just this stack trace.

@andrewbranch andrewbranch added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Needs More Info The issue still hasn't been fully clarified labels Jun 28, 2021
@panta82
Copy link
Author

panta82 commented Jun 29, 2021

@andrewbranch I managed to yank enough stuff from my codebase to create a reproducible mini-project.
https://github.com/panta82/ts-issue-44796

The killer step was when I added:

const errors = getAtPath(formState?.errors, name);

Obviously, this library react-hook-form has an unbound recursive type, and combination of these usages causes tsc to fill in some internal Set beyond what v8 can support, instead of aborting. I think.

Will probably need to be dug into by someone who is a ts expert.

@andrewbranch
Copy link
Member

Fantastic, thanks @panta82!

@andrewbranch andrewbranch removed the Needs More Info The issue still hasn't been fully clarified label Jun 29, 2021
@andrewbranch andrewbranch self-assigned this Jun 29, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.4.1 (RC) milestone Jun 29, 2021
@andreialecu
Copy link

Possibly related: #45249.

recursiveTypeRelatedTo taking most of the CPU time there too, except it doesn't crash, just results in performance issues.

@andrewbranch
Copy link
Member

This looks like it’s already fixed—no crash in 4.4-beta or nightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants