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

zod > 3.22.2 causes JavaScript heap out of memory when running tsc #2962

Closed
florianmutter opened this issue Nov 14, 2023 · 9 comments
Closed

Comments

@florianmutter
Copy link

Versions:

nodejs: 18.17.0
typescript: 5.2.2

We get the following error when updating zod to 3.22.3 or 3.22.4 and running tsc:

$ tsc

<--- Last few GCs --->

[17523:0x160078000]    93868 ms: Scavenge 4044.0 (4128.4) -> 4036.7 (4128.9) MB, 4.5 / 0.0 ms  (average mu = 0.770, current mu = 0.506) allocation failure; 
[17523:0x160078000]    93875 ms: Scavenge 4044.2 (4128.9) -> 4037.0 (4129.4) MB, 4.5 / 0.0 ms  (average mu = 0.770, current mu = 0.506) allocation failure; 
[17523:0x160078000]    93882 ms: Scavenge 4044.5 (4129.4) -> 4037.3 (4145.4) MB, 4.7 / 0.0 ms  (average mu = 0.770, current mu = 0.506) allocation failure; 


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1009666e4 node::Abort() [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 2: 0x1009668c8 node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 3: 0x100abd60c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 4: 0x100c67ec4 v8::internal::EmbedderStackStateScope::EmbedderStackStateScope(v8::internal::Heap*, v8::internal::EmbedderStackStateScope::Origin, cppgc::EmbedderStackState) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 5: 0x100c6686c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 6: 0x100c5a900 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 7: 0x100c5b144 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 8: 0x100c410c4 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
 9: 0x100fe16c0 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
10: 0x10133104c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/p306268/.nodenv/versions/18.17.0/bin/node]
11: 0x1067ae514 
12: 0x106ed0fe8 
13: 0x106816574 
14: 0x106256010 
15: 0x106d26c70 
16: 0x106d0de3c 
17: 0x1070b89ac 
18: 0x106fb472c 
19: 0x106d295e8 
20: 0x106fd9008 
21: 0x106257c18 
22: 0x106d29538 
23: 0x106fd9008 
24: 0x106257c18 
25: 0x1070b96c8 
26: 0x106fb472c 
27: 0x106d295e8 
28: 0x106fd9008 
29: 0x106257c18 
30: 0x106d29538 
31: 0x106fd9008 
32: 0x106257c18 
33: 0x1070b96c8 
34: 0x106fb472c 
35: 0x106d295e8 
36: 0x106fd9008 
37: 0x106257c18 
38: 0x106d29538 
39: 0x106fd9008 
40: 0x106257c18 
41: 0x1070b96c8 
42: 0x106fb472c 
43: 0x106d295e8 
44: 0x106fd9008 
45: 0x106257c18 
46: 0x106d29538 
47: 0x106fd9008 
48: 0x106257c18 
49: 0x1070b96c8 
50: 0x106fb472c 
51: 0x106d295e8 
52: 0x106fd9008 
53: 0x106257c18 
54: 0x106d29538 
55: 0x106fd9008 
56: 0x106257c18 
57: 0x1070b96c8 
58: 0x106fb472c 
59: 0x106d295e8 
60: 0x106fd9008 
61: 0x106257c18 
62: 0x106d29538 
63: 0x106fd9008 
64: 0x106257c18 
65: 0x1070b96c8 
66: 0x106fb472c 
67: 0x106d295e8 
68: 0x106fd9008 
69: 0x106257c18 
70: 0x106d29258 
71: 0x106fd9008 
72: 0x106257c18 
73: 0x1070b96c8 
74: 0x106fb472c 
75: 0x106d295e8 
76: 0x106fd9008 
77: 0x106257c18 
78: 0x106d29538 
79: 0x106fd9008 
80: 0x106257c18 
81: 0x1070b96c8 
82: 0x106fb472c 
83: 0x106d295e8 
84: 0x106fd9008 
85: 0x106257c18 
86: 0x106d29538 
87: 0x106fd9008 
88: 0x106257c18 
89: 0x1070b96c8 
90: 0x106fb472c 
91: 0x106d295e8 
92: 0x106fd9008 
93: 0x106257c18 
94: 0x106d29538 
95: 0x106fd9008 
96: 0x106257c18 
97: 0x1070b96c8 
98: 0x106fb472c 
99: 0x106d295e8 
100: 0x106fd9008 
101: 0x106257c18 
102: 0x106d29538 
103: 0x106fd9008 
104: 0x106257c18 
105: 0x106d29538 
106: 0x106fd9008 
107: 0x106257c18 
108: 0x1070b96c8 
109: 0x106fb472c 
110: 0x106d295e8 
111: 0x106fd9008 
112: 0x106257c18 
113: 0x106d29258 
114: 0x106fd9008 
115: 0x106257c18 
116: 0x1070b96c8 
117: 0x106fb472c 
118: 0x106d295e8 
119: 0x106fd9008 
120: 0x106257c18 
121: 0x106d29258 
122: 0x106fd9008 
123: 0x106257c18 
124: 0x106993134 
125: 0x106257f30 
126: 0x106258058 
127: 0x106d29538 
128: 0x106fd9008 
129: 0x106257c18 
130: 0x106993134 
131: 0x106257f30 
132: 0x106d0ed60 
133: 0x106d29814 
134: 0x106fd9008 
135: 0x106257c18 
136: 0x106816618 
137: 0x106256130 
138: 0x1070b96c8 
139: 0x106fb472c 
140: 0x106d295e8 
141: 0x106fd9008 
142: 0x106257c18 
143: 0x106d29258 
144: 0x106fd9008 
145: 0x106257c18 
146: 0x10695fdd0 
147: 0x1070b77f4 
148: 0x106ee448c 
149: 0x1069a7c28 
150: 0x1069886e0 
151: 0x10681a4b0 
152: 0x106771878 
153: 0x10672afa0 
154: 0x10672046c 
155: 0x10680adb8 
156: 0x107089c98 
157: 0x106732df0 
158: 0x1067619d4 
159: 0x10676530c 
160: 0x10672ae84 
161: 0x10672046c 
162: 0x10680adb8 
163: 0x107089c98 
164: 0x10676eec4 
165: 0x10698a254 
166: 0x10681a4b0 
167: 0x106771878 
168: 0x10672afa0 
169: 0x10672046c 
170: 0x10680adb8 
171: 0x107089c98 
172: 0x106732df0 
173: 0x1067619d4 
174: 0x10676530c 
175: 0x10672ae84 
176: 0x10672046c 
177: 0x10680adb8 
178: 0x107089c98 
179: 0x10676eec4 
180: 0x10698a254 
181: 0x10681a4b0 
182: 0x106771878 
183: 0x10672afa0 
184: 0x10672046c 
185: 0x10680adb8 
186: 0x107089c98 
187: 0x106732df0 
188: 0x1067619d4 
189: 0x10676530c 
190: 0x10672ae84 
191: 0x10672046c 
192: 0x10680adb8 
193: 0x107089c98 
194: 0x10676eec4 
195: 0x10698a254 
196: 0x10681a4b0 
197: 0x106771878 
198: 0x10672afa0 
199: 0x10672046c 
200: 0x10680adb8 
201: 0x107089c98 
202: 0x106732df0 
203: 0x1067619d4 
204: 0x10676530c 
205: 0x10672ae84 
206: 0x10672046c 
207: 0x10680adb8 
208: 0x107089c98 
209: 0x10676eec4 
210: 0x10698a254 
211: 0x10681a4b0 
212: 0x106771878 
213: 0x10672afa0 
214: 0x10672046c 
215: 0x10680adb8 
216: 0x107089c98 
217: 0x106732df0 
218: 0x1067619d4 
219: 0x10676530c 
220: 0x10672ae84 
221: 0x10672046c 
222: 0x10680adb8 
223: 0x107089c98 
224: 0x10676eec4 
225: 0x10698a254 
226: 0x10681a4b0 
227: 0x106771878 
228: 0x10672afa0 
229: 0x10672046c 
230: 0x10680adb8 
231: 0x107089c98 
232: 0x106732df0 
233: 0x1067619d4 
234: 0x10676530c 
235: 0x10672ae84 
236: 0x10672046c 
237: 0x10680adb8 
238: 0x107089c98 
239: 0x10676eec4 
240: 0x10698a254 
241: 0x10681a4b0 
242: 0x106771878 
243: 0x10672afa0 
244: 0x10672046c 
245: 0x10680adb8 
246: 0x107089c98 
247: 0x106732df0 
248: 0x1067619d4 
249: 0x10676530c 
250: 0x10672ae84 
251: 0x10672046c 
252: 0x10680adb8 
253: 0x107089c98 
254: 0x10676eec4 
255: 0x10698a254 
[1]    17523 abort      tsc

I'm happy to add more information if someone tells me what to look for. Our project is fairly big. I have no idea which part might cause this.

Any help appreciated!

@florianmutter florianmutter changed the title zod > 3.22.2 causes JavaScript heap out of memory zod > 3.22.2 causes JavaScript heap out of memory when running tsc Nov 14, 2023
@florianmutter florianmutter changed the title zod > 3.22.2 causes JavaScript heap out of memory when running tsc zod > 3.22.2 causes JavaScript heap out of memory when running tsc Nov 14, 2023
@florianmutter
Copy link
Author

Trying with typescript 5.4.0-dev.20231113 gives the same error.

@danh-luong
Copy link

Hi @florianmutter, I find this article may help you identify the hot spot.

@Swiftwork
Copy link

Did the same upgrade and ran into the same memory leak issue going from 3.22.3 > 3.22.4

@iamelevich
Copy link

Did the same upgrade and ran into the same memory leak issue going from 3.22.3 > 3.22.4

For me - yes. "typescript": "~5.3.3"

@florianmutter
Copy link
Author

florianmutter commented Feb 12, 2024

I followed the article linked by @danh-luong and analyze-trace did output the following:

Trace ended unexpectedly
> checkSourceFile: {"path":"/users/florianmutter/developer/ngshop/discover/apps/discover-ui/lib/types/magnolia_page.ts"}

Hot Spots
└─ Check file /users/florianmutter/developer/ngshop/discover/apps/discover-ui/lib/types/magnolia_page.ts (45688ms)
   ├─ Check variable declaration from (line 119, char 7) to (line 131, char 3) (29981ms)
   │  └─ Check expression from (line 119, char 33) to (line 131, char 3) (29981ms)
   │     ├─ Compare types 1045607 and 156392 (17793ms)
   │     │  └─ Compare types 54748 and 156504 (17791ms)
   │     │     └─ Compare types 55074 and 156888 (17788ms)
   │     │        └─ Compare types 55081 and 156911 (17788ms)
   │     │           └─ Compare types 1045729 and 1045728 (17787ms)
   │     │              └─ Compare types 1045735 and 1045733 (17787ms)
   │     │                 └─ Compare types 1045771 and 1045770 (17785ms)
   │     │                    └─ Compare types 1045773 and 1045772 (17785ms)
   │     │                       └─ Compare types 1045807 and 1045806 (17783ms)
   │     │                          └─ Compare types 1045809 and 1045808 (17783ms)
   │     │                             └─ Compare types 1045845 and 1045844 (17782ms)
   │     │                                └─ Compare types 1045847 and 1045846 (17782ms)
   │     │                                   └─ Compare types 1045899 and 1045898 (17779ms)
   │     │                                      └─ Compare types 1045901 and 1045900 (17779ms)
   │     │                                         └─ Compare types 1045951 and 1045950 (17779ms)
   │     │                                            └─ Compare types 1045953 and 1045952 (17778ms)
   │     │                                               └─ Compare types 1045970 and 1045969 (17778ms)
   │     │                                                  └─ Compare types 1045972 and 1045971 (17778ms)
   │     │                                                     └─ Compare types 1046318 and 1046317 (17768ms)
   │     │                                                        └─ Compare types 1046320 and 1046319 (17768ms)
   │     │                                                           └─ Compare types 1046458 and 1046457 (17766ms)
   │     │                                                              └─ Compare types 1046460 and 1046459 (17766ms)
   │     │                                                                 └─ Compare types 1046600 and 1046599 (17765ms)
   │     └─ Check expression from (line 119, char 42) to (line 131, char 2) (12188ms)
   │        └─ Check expression from (line 130, char 12) to (line 130, char 44) (12187ms)
   │           └─ Check expression from (line 130, char 12) to (line 130, char 42) (12187ms)
   │              └─ Check expression from (line 130, char 12) to (line 130, char 33) (12187ms)
   │                 └─ Compare types 156394 and 165671 (12184ms)
   │                    └─ Compare types 156889 and 165838 (12180ms)
   │                       └─ Compare types 156913 and 165841 (12180ms)
   │                          └─ Compare types 165874 and 165873 (12178ms)
   │                             └─ Compare types 165880 and 165878 (12178ms)
   │                                └─ Compare types 165916 and 165915 (12176ms)
   │                                   └─ Compare types 165918 and 165917 (12176ms)
   │                                      └─ Compare types 165965 and 165964 (12175ms)
   │                                         └─ Compare types 165967 and 165966 (12175ms)
   │                                            └─ Compare types 166003 and 166002 (12175ms)
   │                                               └─ Compare types 166005 and 166004 (12174ms)
   │                                                  └─ Compare types 166055 and 166054 (12173ms)
   │                                                     └─ Compare types 166057 and 166056 (12173ms)
   │                                                        └─ Compare types 166107 and 166106 (12173ms)
   │                                                           └─ Compare types 166109 and 166108 (12173ms)
   │                                                              └─ Compare types 166137 and 166136 (12171ms)
   │                                                                 └─ Compare types 166139 and 166138 (12171ms)
   │                                                                    └─ Compare types 166602 and 166601 (12166ms)
   │                                                                       └─ Compare types 166604 and 166603 (12166ms)
   │                                                                          └─ Compare types 166790 and 166789 (12164ms)
   │                                                                             └─ Compare types 166792 and 166791 (12164ms)
   │                                                                                └─ Compare types 166977 and 166976 (12160ms)
   └─ Check variable declaration from (line 133, char 14) to (line 140, char 17) (15599ms)
      └─ Check expression from (line 133, char 34) to (line 140, char 15) (15599ms)
         └─ Check expression from (line 133, char 34) to (line 139, char 5) (15599ms)
            └─ Compare types 2067438 and 156392 (15536ms)
               └─ Compare types 49940 and 156504 (15536ms)
                  └─ Compare types 55417 and 156888 (15534ms)
                     └─ Compare types 55424 and 156911 (15534ms)
                        └─ Compare types 2067555 and 1045728 (15534ms)
                           └─ Compare types 2067558 and 1045733 (15534ms)
                              └─ Compare types 2067574 and 1045770 (15533ms)
                                 └─ Compare types 2067575 and 1045772 (15533ms)
                                    └─ Compare types 2067590 and 1045806 (15533ms)
                                       └─ Compare types 2067591 and 1045808 (15533ms)
                                          └─ Compare types 2067607 and 1045844 (15526ms)
                                             └─ Compare types 2067608 and 1045846 (15526ms)
                                                └─ Compare types 2067640 and 1045898 (15525ms)
                                                   └─ Compare types 2067641 and 1045900 (15525ms)
                                                      └─ Compare types 2067661 and 1045950 (15525ms)
                                                         └─ Compare types 2067662 and 1045952 (15525ms)
                                                            └─ Compare types 2067671 and 1045969 (15525ms)
                                                               └─ Compare types 2067672 and 1045971 (15525ms)
                                                                  └─ Compare types 2067822 and 1046317 (15521ms)
                                                                     └─ Compare types 2067823 and 1046319 (15521ms)
                                                                        └─ Compare types 2067883 and 1046457 (15519ms)
                                                                           └─ Compare types 2067884 and 1046459 (15519ms)
                                                                              └─ Compare types 2067945 and 1046599 (15518ms)

Duplicate packages
├─ next
│  ├─ Version 12.3.4 from /Users/florianmutter/Developer/ngshop/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next
│  └─ Version 13.4.19 from /Users/florianmutter/Developer/ngshop/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/next
└─ zod
   ├─ Version 3.22.2 from /Users/florianmutter/Developer/ngshop/node_modules/.pnpm/[email protected]/node_modules/zod
   └─ Version 3.22.4 from /Users/florianmutter/Developer/ngshop/node_modules/.pnpm/[email protected]/node_modules/zod

We do use pnpm in a mono repo with pnpm workspaces. The different zod versions referenced by our apps seemed to have been the issue. I update zod everywhere to 3.22.4 and ran pnpm upgrade to update the lock file and the issue was gone. My assumption is that multiple zod versions did cause the issue.

@florianmutter
Copy link
Author

I'm closing this issue because we could fix the issue in our repo.

@loicknuchel
Copy link

Got the same issue with different versions of Zod in my packages.
Not sure what is causing that but quite perturbing...

@Wildhoney
Copy link

Can be fixed with adding a resolutions field to your root package.json as it's probably cause by multiple versions of Zod.

For example:

"resolutions": {
  "zod": "3.22.4"
}

@PatizonP
Copy link

I had the same issue. After upgrade to the same zod version in whole monorepo working well!.

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

No branches or pull requests

7 participants