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]: JavaScript heap out of memory in CI with tsc with @babel/types 7.18.9 #14767

Closed
1 task
jlowcs opened this issue Jul 18, 2022 · 11 comments
Closed
1 task
Labels
area: typescript i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types

Comments

@jlowcs
Copy link
Contributor

jlowcs commented Jul 18, 2022

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/eslint-parser

Input code

tsc -p tsconfig.json

Configuration file name

No response

Configuration

Our project uses typescript with "allowJs": true. Other projects with "allowJs": false don't seem to have the issue.

babel.config.js:

module.exports = api => {
  api.cache(true);
  return {
    sourceType: 'unambiguous',
    presets: [
      [
        '@babel/preset-env',
        {
          useBuiltIns: 'entry',
          corejs: 3,
          loose: false,
          targets: { node: '16' },
        },
      ],
      '@babel/preset-typescript',
    ],
  };
};

Current and expected behavior

The following exception appears in circleci:

> tsc -p tsconfig.json


<--- Last few GCs --->

[107:0x619f070]   103861 ms: Mark-sweep (reduce) 2031.4 (2070.3) -> 2031.4 (2070.3) MB, 2074.3 / 0.0 ms  (average mu = 0.136, current mu = 0.000) last resort GC in old space requested
[107:0x619f070]   105944 ms: Mark-sweep (reduce) 2031.4 (2070.3) -> 2031.4 (2070.3) MB, 2082.9 / 0.0 ms  (average mu = 0.073, current mu = 0.000) last resort GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 0xb00e10 node::Abort() [node]
 2: 0xa1823b node::FatalError(char const*, char const*) [node]
 3: 0xcee09e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xcee417 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xea65d5  [node]
 6: 0xeb8a58 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 7: 0xe79b12 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
 8: 0xe7443c v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [node]
 9: 0xe74515 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [node]
10: 0x10dd41e v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Allocate<v8::internal::Isolate>(v8::internal::Isolate*, int, v8::internal::AllocationType) [node]
11: 0x10dd4d3 v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash<v8::internal::Isolate>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashMap>, int) [node]
12: 0x11e9805 v8::internal::Runtime_MapGrow(int, unsigned long*, v8::internal::Isolate*) [node]
13: 0x15e7cf9  [node]
Aborted (core dumped)

I couldn't reproduce on my own computer.

Environment

  • Babel 7.18.6 + @babel/types 7.18.9 (same issue with Babel full 7.18.9)
  • TypeScript 4.7.4
  • Node 16.13.2
  • npm 8.1.2

Possible solution

No response

Additional context

I initially bumped @babel/preset-env, then tried bumping each of its updated dependencies separately in the lockfile to pinpoint the culprit, which ended up being @babel/types.

I only see #14763 as a recent PR on @babel/types. Not sure how this could impact tsc.

@babel-bot
Copy link
Collaborator

Hey @jlowcs! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@JLHwung
Copy link
Contributor

JLHwung commented Jul 19, 2022

tsc -p tsconfig.json

It seems to me the GC error occurs when you are running tsc. How does tsc invoke @babel/eslint-parser? Can you provide a reproduction repo?

@jlowcs
Copy link
Contributor Author

jlowcs commented Jul 19, 2022

I don't see why tsc would call eslint-parser tbh.

I'm thinking tsc is just loading the babel types for some reason, and that's what causes the GC error.

It's gonna be tricky and time consuming to provide a reproduction repo since I'm only seeing the issue in the CI. I don't know when I'll have any available time to put into that.

I could maybe try running tsc in debug mode to try and see why it's attempting to load the babel types.

@liuxingbaoyu
Copy link
Member

I could maybe try running tsc in debug mode to try and see why it's attempting to load the babel types.

An easy way, you can add a console.trace to the @babel/eslint-parser or @babel/types entry.

@jlowcs
Copy link
Contributor Author

jlowcs commented Jul 19, 2022

I noticed that @babel/types was an indirect dependency of jest:

└─┬ jest@27.5.1
  └─┬ @jest/core@27.5.1
    ├─┬ jest-config@27.5.1
    │ └─┬ babel-jest@27.5.1
    │   ├─┬ @types/babel__core@7.1.18
    │   │ ├── @babel/types@7.18.9 deduped
    │   │ ├─┬ @types/babel__generator@7.6.4
    │   │ │ └── @babel/types@7.18.9 deduped
    │   │ └─┬ @types/babel__template@7.4.1
    │   │   └── @babel/types@7.18.9 deduped
    │   └─┬ babel-preset-jest@27.5.1
    │     └─┬ babel-plugin-jest-hoist@27.5.1
    │       └── @babel/types@7.18.9 deduped

So I tried deleting @types/babel_* before running tsc, and the issue disappears. Meaning that tsc apparently tries to load the @types/babel_* types, which results in loading @babel/types, which results in the GC error.

I was able to pinpoint the version of @babel/types the issue started appearing on. It's indeed 7.18.9. 7.18.8 does not appear to have the issue.

Not sure where to go from there.

@liuxingbaoyu
Copy link
Member

liuxingbaoyu commented Jul 19, 2022

It's interesting. Your feedback is also very helpful!

I found in your bug report that there is an OOM when the memory reaches 2GB.
Can you reproduce it if you add a memory limit locally (--max-old-space-size=2048)?

Actually I'm not sure this is a technical bug, 2GB of RAM is a bit small.😕

@JLHwung
Copy link
Contributor

JLHwung commented Jul 19, 2022

It's indeed 7.18.9. 7.18.8 does not appear to have the issue.

Can you reproduce this issue on 7.18.8 with a smaller memory limit, i.e. --max-old-space-size=1536? If no then we should investigate the causes of significant memory usage.

@liuxingbaoyu
Copy link
Member

I'm closing it now due to long periods of inactivity, feel free to reopen it if the problem persists.

@sadikassistivlabs
Copy link

FYI I have been consistently running into this on a Github Actions hosted runner using ubuntu-latest, and the project includes jest@29.1.2 that transitively pulls in @babel/types@7.19.4

I don't have a minimal shareable reproduction at the moment, but I did run a performance profile of tsc locally (where it still works fine) following these instructions - https://github.com/microsoft/TypeScript/wiki/Performance#performance-tracing I found in the thread for the tsc side of this issue - microsoft/TypeScript#44299

The output coming from @babel/types is enormous and so it won't fit into a comment (also I don't quite know what to make of it yet), but here's a very small snippet of it

Hot Spots
└─ Check file �[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m (2737ms)
   ├─ Compare types 195585 and 194272 (1490ms)
   │  └─ Compare types 197843 and 194272 (1422ms)
   │     ├─ {"id":197843,"kind":"Union","count":252,"types":[197591,197592,197593,197594,197595,197596,197597,197598,197599,197600,197601,197602,197603,197604,197605,197606,197607,197608,197609,197610,197611,197612,197613,197614,197615,197616,197617,197618,197619,197620,197621,197622,197623,197624,197625,197626,197627,197628,197629,197630,197631,197632,197633,197634,197635,197636,197637,197638,197639,197640,197641,197642,197643,197644,197645,197646,197647,197648,197649,197650,197651,197652,197653,197654,197655,197656,197657,197658,197659,197660,197661,197662,197663,197664,197665,197666,197667,197668,197669,197670,197671,197672,197673,197674,197675,197676,197677,197678,197679,197680,197681,197682,197683,197684,197685,197686,197687,197688,197689,197690,197691,197692,197693,197694,197695,197696,197697,197698,197699,197700,197701,197702,197703,197704,197705,197706,197707,197708,197709,197710,197711,197712,197713,197714,197715,197716,197717,197718,197719,197720,197721,197722,197723,197724,197725,197726,197727,197728,197729,197730,197731,197732,197733,197734,197735,197736,197737,197738,197739,197740,197741,197742,197743,197744,197745,197746,197747,197748,197749,197750,197751,197752,197753,197754,197755,197756,197757,197758,197759,197760,197761,197762,197763,197764,197765,197766,197767,197768,197769,197770,197771,197772,197773,197774,197775,197776,197777,197778,197779,197780,197781,197782,197783,197784,197785,197786,197787,197788,197789,197790,197791,197792,197793,197794,197795,197796,197797,197798,197799,197800,197801,197802,197803,197804,197805,197806,197807,197808,197809,197810,197811,197812,197813,197814,197815,197816,197817,197818,197819,197820,197821,197822,197823,197824,197825,197826,197827,197828,197829,197830,197831,197832,197833,197834,197835,197836,197837,197838,197839,197840,197841,197842]}
   │     │  ├─ {"id":197591,"kind":"Intersection","count":2,"types":[195589,195585]}
   │     │  │  ├─ {"id":195589,"kind":"AliasedConditionalType","name":"Extract","aliasTypeArguments":[192930,195584],"conditionalCheckType":192930,"conditionalExtendsType":195584,"conditionalTrueType":195842,"conditionalFalseType":23,"location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36mtypescript�[39m�[35m/lib/lib.es5.d.ts�[39m","line":1571,"char":1}}
   │     │  │  │  ├─ {"id":192930,"kind":"Object","name":"AnyTypeAnnotation","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":625,"char":1}}
   │     │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  ├─ {"id":195842,"kind":"Intersection","count":2,"types":[195584,192930]}
   │     │  │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  │  └─ {"id":192930,"kind":"Object","name":"AnyTypeAnnotation","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":625,"char":1}}
   │     │  │  │  └─ {"id":23,"kind":"Intrinsic","name":"never"}
   │     │  │  └─ {"id":195585,"kind":"TypeParameter","name":"P","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":45}}
   │     │  ├─ {"id":197592,"kind":"Intersection","count":2,"types":[195590,195585]}
   │     │  │  ├─ {"id":195590,"kind":"AliasedConditionalType","name":"Extract","aliasTypeArguments":[192931,195584],"conditionalCheckType":192931,"conditionalExtendsType":195584,"conditionalTrueType":195845,"conditionalFalseType":23,"location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36mtypescript�[39m�[35m/lib/lib.es5.d.ts�[39m","line":1571,"char":1}}
   │     │  │  │  ├─ {"id":192931,"kind":"Object","name":"ArgumentPlaceholder","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":1035,"char":1}}
   │     │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  ├─ {"id":195845,"kind":"Intersection","count":2,"types":[195584,192931]}
   │     │  │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  │  └─ {"id":192931,"kind":"Object","name":"ArgumentPlaceholder","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":1035,"char":1}}
   │     │  │  │  └─ {"id":23,"kind":"Intrinsic","name":"never"}
   │     │  │  └─ {"id":195585,"kind":"TypeParameter","name":"P","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":45}}
   │     │  ├─ {"id":197593,"kind":"Intersection","count":2,"types":[195591,195585]}
   │     │  │  ├─ {"id":195591,"kind":"AliasedConditionalType","name":"Extract","aliasTypeArguments":[192932,195584],"conditionalCheckType":192932,"conditionalExtendsType":195584,"conditionalTrueType":195848,"conditionalFalseType":23,"location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36mtypescript�[39m�[35m/lib/lib.es5.d.ts�[39m","line":1571,"char":1}}
   │     │  │  │  ├─ {"id":192932,"kind":"Object","name":"ArrayExpression","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":39,"char":1}}
   │     │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  ├─ {"id":195848,"kind":"Intersection","count":2,"types":[195584,192932]}
   │     │  │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  │  └─ {"id":192932,"kind":"Object","name":"ArrayExpression","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":39,"char":1}}
   │     │  │  │  └─ {"id":23,"kind":"Intrinsic","name":"never"}
   │     │  │  └─ {"id":195585,"kind":"TypeParameter","name":"P","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":45}}
   │     │  ├─ {"id":197594,"kind":"Intersection","count":2,"types":[195592,195585]}
   │     │  │  ├─ {"id":195592,"kind":"AliasedConditionalType","name":"Extract","aliasTypeArguments":[192933,195584],"conditionalCheckType":192933,"conditionalExtendsType":195584,"conditionalTrueType":195851,"conditionalFalseType":23,"location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36mtypescript�[39m�[35m/lib/lib.es5.d.ts�[39m","line":1571,"char":1}}
   │     │  │  │  ├─ {"id":192933,"kind":"Object","name":"ArrayPattern","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":356,"char":1}}
   │     │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  ├─ {"id":195851,"kind":"Intersection","count":2,"types":[195584,192933]}
   │     │  │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  │  └─ {"id":192933,"kind":"Object","name":"ArrayPattern","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":356,"char":1}}
   │     │  │  │  └─ {"id":23,"kind":"Intrinsic","name":"never"}
   │     │  │  └─ {"id":195585,"kind":"TypeParameter","name":"P","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":45}}
   │     │  ├─ {"id":197595,"kind":"Intersection","count":2,"types":[195593,195585]}
   │     │  │  ├─ {"id":195593,"kind":"AliasedConditionalType","name":"Extract","aliasTypeArguments":[192934,195584],"conditionalCheckType":192934,"conditionalExtendsType":195584,"conditionalTrueType":195854,"conditionalFalseType":23,"location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36mtypescript�[39m�[35m/lib/lib.es5.d.ts�[39m","line":1571,"char":1}}
   │     │  │  │  ├─ {"id":192934,"kind":"Object","name":"ArrayTypeAnnotation","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":628,"char":1}}
   │     │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  ├─ {"id":195854,"kind":"Intersection","count":2,"types":[195584,192934]}
   │     │  │  │  │  ├─ {"id":195584,"kind":"AnonymousType","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":69}}
   │     │  │  │  │  └─ {"id":192934,"kind":"Object","name":"ArrayTypeAnnotation","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":628,"char":1}}
   │     │  │  │  └─ {"id":23,"kind":"Intrinsic","name":"never"}
   │     │  │  └─ {"id":195585,"kind":"TypeParameter","name":"P","location":{"path":"�[35m/users/sadikshahidain/source/assistivlabs/node_modules/�[36m@babel/types�[39m�[35m/lib/index.d.ts�[39m","line":2819,"char":45}}
   │     │  ├─ {"id":197596,"kind":"Intersection","count":2,"types":[195594,195585]}

@liuxingbaoyu
Copy link
Member

@sadikassistivlabs What version of nodejs and typescript are you using? Have you tried https://www.typescriptlang.org/docs/handbook/nightly-builds.html?

@sadikassistivlabs
Copy link

https://www.typescriptlang.org/docs/handbook/nightly-builds.html

Node 14.20.0 and Typescript 4.6.3

And not yet, but the next thing for me to try is upgrading to the latest stable TS, as someone in that other thread said it fixed things for them

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types
Projects
None yet
Development

No branches or pull requests

5 participants