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

5.1 regression from 5.0: JavaScript heap out of memory (Type instantiation is excessively deep and possibly infinit) #54542

Closed
melroy89 opened this issue Jun 5, 2023 · 19 comments · Fixed by #54781 · May be fixed by #54754
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.

Comments

@melroy89
Copy link

melroy89 commented Jun 5, 2023

Bug Report

5.0.4 used to work fine after upgrading to the current latest version 5.1.3. Very slow builds and eventually crashes. My root-cause seems to be a circular issue of some sort with tsc.

Seems like tsc can't handle interface definition files anymore, in this case from lodash?

node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.

194     interface Object<T> extends LoDashImplicitWrapper<T> {
                  ~~~~~~

node_modules/@types/lodash/common/common.d.ts:206:15 - error TS2430: Interface 'ObjectChain<T>' incorrectly extends interface 'LoDashExplicitWrapper<T>'.
  The types returned by 'entries().pop()' are incompatible between these types.
    Type 'CollectionChain<string | T[keyof T]>' is missing the following properties from type 'ObjectChain<[string, any]>': assign, assignIn, assignInWith, assignWith, and 11 more.

206     interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
                  ~~~~~~~~~~~

My workaround was adding "skipLibCheck": true to the tsconfig.json did mitigate the issue for now.

node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.

194     interface Object<T> extends LoDashImplicitWrapper<T> {
                  ~~~~~~

node_modules/@types/lodash/common/common.d.ts:206:15 - error TS2430: Interface 'ObjectChain<T>' incorrectly extends interface 'LoDashExplicitWrapper<T>'.
  The types returned by 'entries().pop()' are incompatible between these types.
    Type 'CollectionChain<string | T[keyof T]>' is missing the following properties from type 'ObjectChain<[string, any]>': assign, assignIn, assignInWith, assignWith, and 11 more.

206     interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
                  ~~~~~~~~~~~

Workaround for me was to add: "skipLibCheck": true to the tsconfig.json did mitigate the issue for now.

🔎 Search Terms

  • Crash
  • OOME
  • 5.1
  • Heap

🕗 Version & Regression Information

I also tried the latest next tag, with the same issues.

  • This is a crash
  • This changed between versions 5.0.x and 5.1.x

⏯ Playground Link

The "Type is excessively deep" is being triggered in a project that includes this the @types/lodash, so in your package.json be sure you have the dependency:

"dependencies": {
     "lodash": "^4.17.21"
},
"devDependencies": {
    "@types/lodash": "^4.14.195"   
}

Be sure that you did NOT set skipLibCheck to true. So keep it to false, otherwise the d.ts files will be ignored.

Execute via: NODE_OPTIONS=--max-old-space-size=8192 tsc --pretty --diagnostics --extendedDiagnostics --incremental false

💻 Code

See below, it doesn't involve my code.

🙁 Actual behavior

JavaScript heap out of memory, because of circular/ too deep dependency?

node_modules/@types/lodash/common/common.d.ts:194:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.

194     interface Object<T> extends LoDashImplicitWrapper<T> {
                  ~~~~~~

node_modules/@types/lodash/common/common.d.ts:206:15 - error TS2430: Interface 'ObjectChain<T>' incorrectly extends interface 'LoDashExplicitWrapper<T>'.
  The types returned by 'entries().pop()' are incompatible between these types.
    Type 'CollectionChain<string | T[keyof T]>' is missing the following properties from type 'ObjectChain<[string, any]>': assign, assignIn, assignInWith, assignWith, and 11 more.

206     interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
                  ~~~~~~~~~~~
Found 2 errors in 1 file.

Errors  Files
     2  node_modules/@types/lodash/common/common.d.ts:194
Files:                          253
Lines of Library:              9875
Lines of Definitions:         73521
Lines of TypeScript:           3999
Lines of JavaScript:              0
Lines of JSON:                    0
Lines of Other:                   0
Identifiers:                 117524
Symbols:                    4856905
Types:                      1093043
Instantiations:            11883895
Memory used:               2379915K
Assignability cache size:    230447
Identity cache size:            772
Subtype cache size:             398
Strict subtype cache size:       10
I/O Read time:                0.15s
Parse time:                   1.17s
ResolveModule time:           0.21s
ResolveTypeReference time:    0.03s
ResolveLibrary time:          0.02s
Program time:                 1.70s
Bind time:                    0.47s
Check time:                 239.51s
transformTime time:           0.05s
Source Map time:              0.02s
commentTime time:             0.04s
I/O Write time:               0.02s
printTime time:               0.37s
Emit time:                    0.37s
Total time:                 242.05s

🙂 Expected behavior

No crashes or errors during tsc!

@melroy89 melroy89 changed the title 5.1 regression from 5.0: JavaScript heap out of memory 5.1 regression from 5.0: JavaScript heap out of memory (Type instantiation is excessively deep and possibly infinit) Jun 5, 2023
bjorngi pushed a commit to navikt/unleash-me that referenced this issue Jun 6, 2023
@ahejlsberg
Copy link
Member

ahejlsberg commented Jun 6, 2023

I can repo this with a simple single-file project that just imports @types/lodash, but only when strict mode is disabled:

// compile without --strict
import "lodash";

No problems when compiling with --strict enabled. The runaway type check happens when computing variance information for type ObjectChain<T>. A quick workaround is to change one of the declarations of ObjectChain<T> to ObjectChain<in out T>. This asserts that the type is invariant which skips the variance computation.

@ahejlsberg ahejlsberg added Bug A bug in TypeScript Recent Regression This is a new regression just found in the last major/minor version of TypeScript. labels Jun 6, 2023
@ahejlsberg ahejlsberg added this to the TypeScript 5.1.4 milestone Jun 6, 2023
@ahejlsberg
Copy link
Member

@RyanCavanaugh @DanielRosenwasser FYI.

@ahejlsberg
Copy link
Member

Hoping someone has time to bisect this so we can identify the source of the issue.

@Andarist
Copy link
Contributor

Andarist commented Jun 6, 2023

Bisected to #52106

Oppzippy added a commit to Oppzippy/recruitment-bot that referenced this issue Jun 6, 2023
typescript is pinned to 5.0.x because of the following issue:
microsoft/TypeScript#54542
@ahejlsberg
Copy link
Member

@weswigham FYI

@jakebailey
Copy link
Member

Wild guess, but this may be the cause of the OOM in typescript-eslint/typescript-eslint#7088 based on the timing.

@JoshuaKGoldberg
Copy link
Contributor

Confirmed @jakebailey, great spot - thanks! I bisected in typescript-eslint/typescript-eslint#7091 on the individual TypeScript main commits and 958487b is the first that causes the OOM.

@cami-dev
Copy link

cami-dev commented Jun 15, 2023

Any update on this? Got the same issue when upgrading to typescript 5.1.3 from 4.9.4 and we have @types/lodash : 4.14.195 as devdependencies.

@throrin19
Copy link

throrin19 commented Jun 16, 2023

Same problem with lodash here but with skipLibCheck to true. Any news about this resolution ?

It works fine with typescript 5.0.4

This is my error :

 ../../node_modules/@types/lodash/common/common.d.ts(194,15): error TS2589: Type instantiation is excessively deep and possibly infinite.
       ../../node_modules/@types/lodash/common/common.d.ts(206,15): error TS2430: Interface 'ObjectChain<T>' incorrectly extends interface 'LoDashExplicitWrapper<T>'.
         The types returned by 'entries().pop()' are incompatible between these types.
           Type 'CollectionChain<string | T[keyof T]>' is missing the following properties from type 'ObjectChain<[string, any]>': assign, assignIn, assignInWith, assignWith, and 11 more.

@melroy89
Copy link
Author

melroy89 commented Jun 16, 2023

My workaround for now is to disable interfaces (.d.ts files), using the following code snippet in my local tsconfig.json file:

  "skipLibCheck": true,

More info: https://www.typescriptlang.org/tsconfig#skipLibCheck

@slavede
Copy link

slavede commented Jun 19, 2023

My workaround for now is to disable interfaces (.d.ts files), using the following code snippet in my local tsconfig.json file:

  "skipLibCheck": true,

More info: https://www.typescriptlang.org/tsconfig#skipLibCheck

Important to mention that it is a just temporary workaround as it would skip all libraries check.

@melroy89
Copy link
Author

Important to mention that it is a just temporary workaround as it would skip all libraries check.

Yes workarounds are hopefully temporary in general. I don't like this approach either, but at least I can build again.

@StanislavKharchenko
Copy link

Any chance to fix this?
3 weeks after issue was reported.

@chris-heney
Copy link

Yeah, my serverless framework deploys are broken until this is fixed too.

@DanielRosenwasser
Copy link
Member

Can people following the thread verify that #54781 fixes the issue? You can do so by using a specific build of TypeScript:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/155637/artifacts?artifactName=tgz&fileId=04DE374095785839F62F13D7F462400B471B8FC647A291E41CD31D23BFD6186002&fileName=/typescript-5.2.0-insiders.20230626.tgz"
    }
}

(see #54781 (comment))

@Mr0grog
Copy link

Mr0grog commented Jun 26, 2023

@DanielRosenwasser That build works great and solves the issue for the project where I ran into problems! 🚀

@dcsaszar
Copy link

@DanielRosenwasser Verified. Works for us, too!

@JoshuaKGoldberg
Copy link
Contributor

@DanielRosenwasser confirmed typescript-eslint/typescript-eslint#7088 appears to be fixed, thanks!

@melroy89
Copy link
Author

Sorry for my late response, but I can in fact confirms TypeScript v5.2.2 solved all my issues.

naveennazimudeen pushed a commit to naveennazimudeen/react-quill that referenced this issue Feb 16, 2024
… as rc1 and rc2 requires react-quill changes. upgraded typescript to 5.2.2 to fix issues with lodash microsoft/TypeScript#54542, updated to webpack 5 (webpack@latest) https://www.codingbeautydev.com/blog/error-0308010c-digital-envelope-routines-unsupported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.
Projects
None yet