Open dagstuan opened 3 years ago
Almost (young object promotion failed Allocation failed) exact same issue. obviously must be something specific about our codebase, but verbose outputs nothing so I dont know where we go from here. Perhaps providing some kind of dump might be useful for someone?
Worth noting it happens after a very long time hanging.
<--- Last few GCs --->
[7184:0x110008000] 621386 ms: Mark-sweep (reduce) 4064.9 (4101.8) -> 4064.2 (4103.3) MB, 2424.6 / 0.0 ms (average mu = 0.114, current mu = 0.018) allocation failure scavenge might not succeed
[7184:0x110008000] 624960 ms: Mark-sweep (reduce) 4065.3 (4102.3) -> 4064.5 (4103.5) MB, 3528.9 / 0.0 ms (average mu = 0.056, current mu = 0.013) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
1: 0x1012d84c5 node::Abort() (.cold.1) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
2: 0x1000a5d59 node::Abort() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
3: 0x1000a5ebf node::OnFatalError(char const*, char const*) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
4: 0x1001e8007 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
5: 0x1001e7fa3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
6: 0x100394ea5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
7: 0x1003f0e03 v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject, int) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
8: 0x1003d866b void v8::internal::LiveObjectVisitor::VisitBlackObjectsNoFail<v8::internal::EvacuateNewSpaceVisitor, v8::internal::MajorNonAtomicMarkingState>(v8::internal::MemoryChunk*, v8::internal::MajorNonAtomicMarkingState*, v8::internal::EvacuateNewSpaceVisitor*, v8::internal::LiveObjectVisitor::IterationMode) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
9: 0x1003d81b5 v8::internal::FullEvacuator::RawEvacuatePage(v8::internal::MemoryChunk*, long*) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
10: 0x1003d7ef6 v8::internal::Evacuator::EvacuatePage(v8::internal::MemoryChunk*) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
11: 0x1003f582e v8::internal::PageEvacuationTask::RunInParallel(v8::internal::ItemParallelJob::Task::Runner) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
12: 0x1003af8a2 v8::internal::ItemParallelJob::Task::RunInternal() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
13: 0x1003afd28 v8::internal::ItemParallelJob::Run() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
14: 0x1003d9f65 void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks<v8::internal::FullEvacuator, v8::internal::MarkCompactCollector>(v8::internal::MarkCompactCollector*, v8::internal::ItemParallelJob*, v8::internal::MigrationObserver*, long) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
15: 0x1003d9b66 v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
16: 0x1003c5397 v8::internal::MarkCompactCollector::Evacuate() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
17: 0x1003c2c2b v8::internal::MarkCompactCollector::CollectGarbage() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
18: 0x10039556b v8::internal::Heap::MarkCompact() [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
19: 0x100391b59 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
20: 0x10038f9a0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
21: 0x10039e08a v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
22: 0x10039e111 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
23: 0x10036c1e7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
24: 0x1006eb078 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
25: 0x100a709b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/adamthomas/.nvm/versions/node/v14.14.0/bin/node]
26: 0x2cb8704f923c ```
We're experiencing this against both our front and backend applications which is interesting as they share little code. By any chance is anyone else here using Zod? It's perhaps the most type-complex library which we're using in both.
@brudil Im using Zod too!
@brudil I am also using Zod!
Interesting, using Zod here as well, 3.1.0 and I can't compile typecheck anything anymore since TS 4.3.2
I setup a minimal test case like so:
import zod from 'zod'
export const SchemaExample = zod.object({
name: zod.string().min(1),
description: zod.string().min(1),
})
export type SchemaExampleType = zod.infer<typeof SchemaExample>
Interestingly, in the simple case, this causes "maximum depth" TS errors rather than a hang. I think when you have a lot of calls to Actually you dont need the infer even, or even the schema -- importing zod alone is enough. Not sure exactly how this might ultimately end up in hang when consumed a lot of times in a large codebase. Also not sure what changed in TS to make Zod incompatible.zod.infer
this triggers some infinite recursion/memory leak.
Here are the errors:
node_modules/zod/lib/helpers/partialUtil.d.ts:5:42 - error TS2321: Excessive stack depth comparing types 'ZodError<?>' and 'ZodError<?>'.
5 object: T extends AnyZodObject ? ZodObject<{
~~~~~~~~~~~
6 [k in keyof T["_shape"]]: DeepPartial<T["_shape"][k]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 }, T["_unknownKeys"], T["_catchall"]> : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/helpers/partialUtil.d.ts:5:42 - error TS2321: Excessive stack depth comparing types 'ZodFormattedError<?>' and 'ZodFormattedError<?>'.
5 object: T extends AnyZodObject ? ZodObject<{
~~~~~~~~~~~
6 [k in keyof T["_shape"]]: DeepPartial<T["_shape"][k]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 }, T["_unknownKeys"], T["_catchall"]> : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/helpers/partialUtil.d.ts:5:42 - error TS2321: Excessive stack depth comparing types 'ZodIntersection<?, U>' and 'ZodIntersection<?, U>'.
5 object: T extends AnyZodObject ? ZodObject<{
~~~~~~~~~~~
6 [k in keyof T["_shape"]]: DeepPartial<T["_shape"][k]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 }, T["_unknownKeys"], T["_catchall"]> : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/helpers/partialUtil.d.ts:5:42 - error TS2321: Excessive stack depth comparing types 'ZodIntersection<T, ?>' and 'ZodIntersection<T, ?>'.
5 object: T extends AnyZodObject ? ZodObject<{
~~~~~~~~~~~
6 [k in keyof T["_shape"]]: DeepPartial<T["_shape"][k]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 }, T["_unknownKeys"], T["_catchall"]> : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/helpers/partialUtil.d.ts:5:42 - error TS2321: Excessive stack depth comparing types 'ZodNonEmptyArray<?>' and 'ZodNonEmptyArray<?>'.
5 object: T extends AnyZodObject ? ZodObject<{
~~~~~~~~~~~
6 [k in keyof T["_shape"]]: DeepPartial<T["_shape"][k]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 }, T["_unknownKeys"], T["_catchall"]> : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/helpers/partialUtil.d.ts:5:42 - error TS2321: Excessive stack depth comparing types 'ZodOptional<?>' and 'ZodOptional<?>'.
5 object: T extends AnyZodObject ? ZodObject<{
~~~~~~~~~~~
6 [k in keyof T["_shape"]]: DeepPartial<T["_shape"][k]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 }, T["_unknownKeys"], T["_catchall"]> : never;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:60:168 - error TS2577: Return type annotation circularly references itself.
60 refine: <Func extends (arg: Output) => any, This extends this = this>(check: Func, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)) => ZodEffectsType<This>;
~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:61:162 - error TS2577: Return type annotation circularly references itself.
61 refinement: <This extends this = this>(check: (arg: Output) => any, refinementData: MakeErrorData | ((arg: Output, ctx: RefinementCtx) => MakeErrorData)) => ZodEffectsType<This>;
~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:62:86 - error TS2577: Return type annotation circularly references itself.
62 _refinement<This extends this>(refinement: InternalCheck<Output>["refinement"]): ZodEffectsType<This>;
~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:63:90 - error TS2577: Return type annotation circularly references itself.
63 superRefine: <This extends this>(refinement: InternalCheck<Output>["refinement"]) => ZodEffectsType<This>;
~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:69:68 - error TS2577: Return type annotation circularly references itself.
69 or<T extends ZodTypeAny, This extends this = this>(option: T): This extends ZodUnion<infer Opts> ? [...Opts, T] extends ZodUnionOptions ? ZodUnion<[...Opts, T]> : never : ZodUnion<[This, T]>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:71:97 - error TS2577: Return type annotation circularly references itself.
71 transform<NewOut, This extends this>(transform: (arg: Output) => NewOut | Promise<NewOut>): This extends ZodEffects<infer T, any> ? ZodEffects<T, NewOut> : ZodEffects<This, NewOut>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/zod/lib/types.d.ts:381:18 - error TS2321: Excessive stack depth comparing types 'ZodTuple<?>' and 'ZodTuple<?>'.
381 export interface ZodFunctionDef<Args extends ZodTuple<any> = ZodTuple<any>, Returns extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
~~~~~~~~~~~~~~
Found 13 errors.
FWIW I'm not using Zod, but the codebase is quite large.
Interesting. Perhaps its more t do with anything that uses recursive types.
I'm going to investigate Zod, since there's a repro. Hopefully, the underlying issue will turn out to be the same as @dagstuan's.
Introduced in https://github.com/microsoft/TypeScript/pull/30639 (cc @weswigham). On the bright side, in that exact commit, the toy repro runs out of memory, so we've made improvements since then. :smile:
Yeah, when we merged that we started exploring more types during relationship checking to test for compatibility which, for generatively expanding types, means manufacturing more types (before we hit somewhat arbitrary limiters) - in the intervening time, we've tightened up on some of those limiters/identities a bit, and that's generally how I've been going about "fixing" it - identify costly structures to compare, figure out how they're dodging our complexity limiters, and the update the complexity limiters to capture them.
I'm getting similar error, and I have a (maybe) simpler repro:
import { object, string } from "zod";
const validator = object({
_key: string()
});
That's enough to trigger the excessive stack depth error. My guess is that it has something to do with generic inference.
Okay, it took a while, but here's a toy repro with no imports.
export declare type ZodFormattedError<T> = T extends [any, ...any] ? {
[K in keyof T]?: ZodFormattedError<T[K]>;
} & {
_errors: string[];
} : T extends any[] ? ZodFormattedError<T[number]>[] & {
_errors: string[];
} : T extends object ? {
[K in keyof T]?: ZodFormattedError<T[K]>;
} & {
_errors: string[];
} : {
_errors: string[];
};
export declare class ZodError<T> {
format: () => ZodFormattedError<T>;
}
declare const c1: ZodError<number>;
const c2: ZodError<string> = c1;
Personally, I find it easier to read like this:
type ZodFormattedError<T> = T extends [any, ...any]
? { [K in keyof T]?: ZodFormattedError<T[K]>; } & { _errors: string[]; }
: T extends any[]
? ZodFormattedError<T[number]>[] & { _errors: string[]; }
: T extends object
? { [K in keyof T]?: ZodFormattedError<T[K]>; } & { _errors: string[]; }
: { _errors: string[]; };
interface ZodError<T> {
format: () => ZodFormattedError<T>;
}
declare const c1: ZodError<number>;
const c2: ZodError<string> = c1;
Ooh, if you comment out these lines, it OOMs:
type ZodFormattedError<T> = T extends [any, ...any]
? { [K in keyof T]?: ZodFormattedError<T[K]>; } & { _errors: string[]; }
: T extends any[]
? ZodFormattedError<T[number]>[] & { _errors: string[]; }
// : T extends object
// ? { [K in keyof T]?: ZodFormattedError<T[K]>; } & { _errors: string[]; }
: { _errors: string[]; };
interface ZodError<T> {
format: () => ZodFormattedError<T>;
}
declare const c1: ZodError<number>;
const c2: ZodError<string> = c1;
And pulling out the intersection with { _errors: string[]; }
seems to mitigate the issue.
type ZodFormattedError<T> = { _errors: string[]; } & (T extends [any, ...any]
? { [K in keyof T]?: ZodFormattedError<T[K]>; }
: T extends any[]
? ZodFormattedError<T[number]>[]
: T extends object
? { [K in keyof T]?: ZodFormattedError<T[K]>; }
: {});
(I think I got that right.)
@weswigham Is there something smart we can do with the depth limit in the the toy repros? And does my mitigation look correct enough to submit as a PR to zod?
is this a zod problem or a ts problem? I feel like this might be more of a ts problem, because something changed in ts 4.3 that broke zod
@autumnblazey It's a TS problem, but a zod PR might help people until a new version of TS is released. Also, the proposed change to zod will likely make it faster even after the TS fix.
@dagstuan Do you want to try running https://www.npmjs.com/package/@amcasey/ts-analyze-trace? It might identify a portion of your code (or imported package) that seems to trigger the problem and which you can share without divulging any IP.
I run into the same issue with https://github.com/unional/type-plus.
Essentially similar issue with zod
@amcasey sure thing, thank you for the help!
I ran the trace and figured out that a utility type I wrote a year or so ago to help with redux-form
typings (DeepPartialExceptArrays<T>
) is causing the issue, along with two type guards. I created a repro here. If you leave the tab open it eventually crashes. Without the type guards it works fine, and it also works fine in TS 4.2
Edit: Oh, and it also works fine with only one of the type guards. The issue seems to arise with the intersection type generated by applying both type guards.
Just a note that Zod 3.2 is out and it now works. Still, theres some underlying issue here.
@dagstuan Fantastic! I'll leave it up to @weswigham to decide whether you're seeing the same underlying issue (I suspect so).
I've seen this repeatedly too in different project (can't share the code yet). E.g. usages suretype and meta-types (both of which I'm the author of). (Again, not in these packages per se, but usages of them).
I've stumbled on this many times from at least 3.x. I think TypeScript would benefit from a rather massive bump in meta programming support and much higher limits. I remember back when C++ template programming was unbearably slow, and then about 10 years ago, compilers made a huge leap and started handling meta programming several orders of magnitude faster. I'd love for this to get prio over new features in the language 🙏
Just a note that Zod 3.2 is out and it now works. Still, theres some underlying issue here.
I'm running Zod 3.2 & TS 4.3.4 and I am experiencing this issue.
Update: whoops I believe this was due to a zod/ts version mismatch between my project & a dependency.
Any news on this? I attempted to re-run my repro with 4.4.0-beta and it still fails.
Had same problem since 4.3, also in 4.4.2, only thing I can do is lock TS version in 4.2 😔
I've created a minimal repro here that demonstrates this using Material UI as well. Basically, I'm doing these things:
SomeComponentProps
SomeComponentProps
(my intent here was to make the base props available from within the wrapper component)SomeComponentProps
inside the wrapper component.If I remove the intersection of prop types or the attempt to merge values into one of the base component's props, all compiles well.
I've tried this with ts@next
, ts@4.5.4
, ts@4.5.2
, and ts@4.2.4
, as well as node 14.18.2
and 16.5.0
with the same results. It could just be that I just shouldn't be trying to "forward" base component props in the way that I have, but still, I don't think it should cause a fatal error. It should be detected and thrown instead.
Here's the code from the repro that produces the problem for me:
import React from "react";
import { styled, SxProps, TextField, TextFieldProps } from "@mui/material";
const StyledTextField = styled(TextField)<TextFieldProps>({ // <-- Using this base component
border: "1px solid red"
});
type StyledTextFieldWrapperProps = {
customWidth?: number | string;
sx?: SxProps;
};
const StyledTextFieldWrapper = ({
customWidth,
sx,
...props
}: StyledTextFieldWrapperProps & TextFieldProps) => { // <-- And this intersection which combines the base + wrapper prop types
return <StyledTextField sx={{ width: customWidth, ...sx }} {...props} />; // <-- With this attempt to merge objects (sx prop)
};
export default function App() {
return (
<div>
<StyledTextFieldWrapper customWidth="80%" />
</div>
);
}
Running into OOM errors after upgrading from 4.5.5 to 4.6.2. We're not using zod. Curious if something changed from 4.5 to 4.6 that could cause this problem?
$ tsc --noEmit
<--- Last few GCs --->
[28:0x6298a50] 8[281](https://github.com/myproject/runs/5573794446?check_suite_focus=true#step:2:281)2 ms: Scavenge (reduce) 1021.5 (1041.0) -> 1020.7 (1041.0) MB, 5.1 / 0.0 ms (average mu = 0.116, current mu = 0.010) allocation failure
[28:0x6298a50] 8[283](https://github.com/myproject/runs/5573794446?check_suite_focus=true#step:2:283)0 ms: Scavenge (reduce) 1021.6 (1041.0) -> 1021.0 (1041.3) MB, 6.2 / 0.0 ms (average mu = 0.116, current mu = 0.010) allocation failure
[28:0x6298a50] 83014 ms: Scavenge (reduce) 1021.7 (1041.3) -> 1021.1 (1041.5) MB, 7.8 / 0.0 ms (average mu = 0.116, current mu = 0.010) allocation failure
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xb09980 node::Abort() [/usr/local/bin/node]
2: 0xa1c235 node::FatalError(char const*, char const*) [/usr/local/bin/node]
3: 0xcf77be v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0xcf7b37 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
5: 0xeaf3d5 [/usr/local/bin/node]
6: 0xeafeb6 [/usr/local/bin/node]
7: 0xebe3de [/usr/local/bin/node]
8: 0xebee20 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
9: 0xec1d9e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0xe832da v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
11: 0x11fc026 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x15f0a99 [/usr/local/bin/node]
Aborted (core dumped)
@EvHaus Have you tried using performance tracing to isolate a repro?
I'm also having issues moving from 4.5.5
to 4.6.2
while doing a type check tsc --noEmit -p tsconfig.json
and one component is taking a crazy amount of time when usually the whole process takes between 3 and 8 seconds.
The compoent involved is a Button
created with @stitches/react
so I think there is a pattern here that something is wrong with libraries that are using CSS types perhaps.
I followed the instructions https://github.com/microsoft/TypeScript/wiki/Performance#performance-tracing but no idea if this is a problem on my side or a regression in Typescript 👀
Adding this: the memory usage is constantly increasing but eventually the process ends (I'm on OS X with 32GB RAM)
@EvHaus Have you tried using performance tracing to isolate a repro?
Here's the output I got:
@EvHaus If it were me, I'd try to eliminate that version mismatch for csstype
. Those types can get pretty big and forcing the compiler to compare similar types structurally is a recipe for problems.
Without the corresponding types file, it's hard to be more specific about which types/packages are causing slowdowns. (I'm not sure why you didn't get that output - maybe it gets skipped if the trace is incomplete.) You can use the print-trace-types
script to pretty-print them after the fact.
My issue (slowness with CSS types) doesn't happen with latest 4.7 beta npm i typescript@beta
👀
Unfortunately removing the duplicate csstype
didn't help, but now I'm getting new details in the tracing:
@EvHaus That's a very long time to spend checking the babel types and I'd be interested to know which version you're on. Having said that, it seems like there's little benefit in checking them yourself, so I'd probably build with skipLibCheck
.
@amcasey We're using @babel/types
version 7.17.0
and I've ensured the package is deduplicated. I tried with skipLibCheck
and that fixed the issue 🎉. Looking at the docs for the skipLibCheck
makes me a bit nervous about turning it off. Are we going to lose some type safety as a result of disabling it?
Any ideas what could have changed between 4.5 and 4.6 that could explain this problem? I'm trying to evaluate if it's better to stick to 4.5 or to move to 4.6 with skipLibCheck
on.
@EvHaus skipLibCheck
can alert you to conflicts between your dependencies, but I generally turn it off myself, since it doesn't find problems in the code I'm working on. If you're concerned, you can try skipping the checks locally and running them in CI.
Notable exception: If you hand-author .d.ts files, you probably do not want skipLibCheck
.
Without knowing the specifics, my guess would be that 4.6 does more checking (i.e. catches more bugs) than 4.5 in a way that affects one or more of your dependencies. If you can share an example, I can look for a more specific explanation. If your code isn't available, it's usually possible to isolate a repro using analyze-trace
, though that's obviously more work.
Not sure what you guys did, but typescript@4.8.2
fixed my memory issues. No more OOM failures, and in general I'm seeing TypeScript running MUCH faster. Nice work! 🎉
Also experiencing this with typescript@4.9.4
, after switching my machine from a MacBookPro 2019 (16 Go), to a Windows 11 PC (16 Go also) (nothing else changed : same code base, same command, etc).
We don't use Zod but we have a very large codebase.
We were surprised because it's the first time we see an OOM error with tsc, in 5 years.
I'm seeing this with:
typescript: 4.9.4
zod: 3.21.4
Downgrading to zod: 3.21.2
resolves the issue. Upgrading to typescript: 4.9.5
doesn't make a difference.
Hello, everyone! I'm getting the same error. I had a legacy project and just started changing some js files to Typescript. My tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"noUncheckedIndexedAccess": true,
"allowJs": true,
"outDir": "./dist",
"checkJs": false,
},
}
In my Mac mini (Monterey, M1 2020, 8GB). When I started the build process, I realised the node consumption exceeded 100% CPU usage.
PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG
20928 node 160.0 00:04.77 7/1 0 18 740M+ 0B
It builds with success, though. Otherwise, in my EC2 instance (Ubuntu 22.04.1 LTS, Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz) shows me this error:
<--- Last few GCs --->
[1173:0x6634210] 15930 ms: Mark-sweep (reduce) 481.4 (493.8) -> 481.1 (491.0) MB, 440.3 / 0.0 ms (+ 3.7 ms in 4 steps since start of marking, biggest step 1.7 ms, walltime since start of marking 457 ms) (average mu = 0.283, current mu = 0.279) finaliz[1173:0x6634210] 16090 ms: Scavenge (reduce) 482.2 (491.0) -> 481.4 (491.0) MB, 7.7 / 0.0 ms (average mu = 0.283, current mu = 0.279) allocation failure;
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xbbf330 node::Abort() [node]
2: 0xad464e [node]
3: 0xda4320 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
4: 0xda46d6 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
5: 0xfa1b65 [node]
6: 0xfa2116 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
7: 0xfb371d [node]
8: 0xfb4235 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xfb69d8 v8::internal::Heap::HandleGCRequest() [node]
10: 0xf306f7 v8::internal::StackGuard::HandleInterrupts() [node]
11: 0x137441f v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x17fb2f9 [node]
Aborted (core dumped)
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1933 ubuntu 20 0 790632 234228 29876 R 93.7 23.7 0:03.81 node
I tried to increase the --max_old_space_size
, but it seems stuck.
Node version: v14.21.3
I tried typescript version 4.2.4 and the latest, 4.9.5.
Am I doing something wrong?
Hello, everyone! I'm getting the same error. I had a legacy project and just started changing some js files to Typescript. My tsconfig:
{ "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "es2017", "sourceMap": true, "incremental": true, "skipLibCheck": true, "strictNullChecks": true, "noImplicitAny": true, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "noUncheckedIndexedAccess": true, "allowJs": true, "outDir": "./dist", "checkJs": false, }, }
In my Mac mini (Monterey, M1 2020, 8GB). When I started the build process, I realised the node consumption exceeded 100% CPU usage.
PID COMMAND %CPU TIME #TH #WQ #PORT MEM PURG 20928 node 160.0 00:04.77 7/1 0 18 740M+ 0B
It builds with success, though. Otherwise, in my EC2 instance (Ubuntu 22.04.1 LTS, Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz) shows me this error:
<--- Last few GCs ---> [1173:0x6634210] 15930 ms: Mark-sweep (reduce) 481.4 (493.8) -> 481.1 (491.0) MB, 440.3 / 0.0 ms (+ 3.7 ms in 4 steps since start of marking, biggest step 1.7 ms, walltime since start of marking 457 ms) (average mu = 0.283, current mu = 0.279) finaliz[1173:0x6634210] 16090 ms: Scavenge (reduce) 482.2 (491.0) -> 481.4 (491.0) MB, 7.7 / 0.0 ms (average mu = 0.283, current mu = 0.279) allocation failure; <--- JS stacktrace ---> FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xbbf330 node::Abort() [node] 2: 0xad464e [node] 3: 0xda4320 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 4: 0xda46d6 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 5: 0xfa1b65 [node] 6: 0xfa2116 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node] 7: 0xfb371d [node] 8: 0xfb4235 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 9: 0xfb69d8 v8::internal::Heap::HandleGCRequest() [node] 10: 0xf306f7 v8::internal::StackGuard::HandleInterrupts() [node] 11: 0x137441f v8::internal::Runtime_StackGuardWithGap(int, unsigned long*, v8::internal::Isolate*) [node] 12: 0x17fb2f9 [node] Aborted (core dumped)
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1933 ubuntu 20 0 790632 234228 29876 R 93.7 23.7 0:03.81 node
I tried to increase the
--max_old_space_size
, but it seems stuck. Node version: v14.21.3I tried typescript version 4.2.4 and the latest, 4.9.5.
Am I doing something wrong?
Experiencing the same here on my MBP with M2 Pro.
Having this (or similar) issue with zod 3.20.6 and typescript 4.8.2
I guess there's another issue about JavaScript heap out of memory
errors over here (about 4.9.3
):
Still getting this issue. I'm getting the following error:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
when running tsc --pretty --noEmit
even if I set the space size like the following:
cross-env NODE_OPTIONS=--max-old-space-size=10240 tsc --pretty --noEmit
I've also had an issue with moving to typescript ~5.1 (or even ~5.0 TBH) in a React components library (it uses mui),
Here's how I resolved the TS2590: Expression produces a union type that is too complex to represent
error:
tsx files:
// Changed
<StyledChip variant={variant} {...otherProps}>
// To
<StyledChip
variant={variant as TChipVariants}
{...(otherProps as React.HTMLAttributes<HTMLDivElement>)}
>
And
// Changed
{...otherProps}
// To
const { sx, ...restProps } = otherProps
...
<StyledRadioGroup {...restProps} >
But had to increase max-old-space-size dramatically to 16384 in order to get the relevant errors.. I hope it helps anyone..
If anyone needs a quick/temp fix: downgrading to 4.2.4
fixed the problem for me.
Using MUI (I'm using MUI v5.14.16) may give the heap-out-of-memory error. Upgrading the TS to 4.2.4
[reference] solves the problem if I continue using the SxProps
of MUI. (After playing with setting the heap, tried upgrading to the latest TS version, but no luck.)
I have a util type CreateComponentProps
that's used when creating a component prop type, and it's used throughout my React codebase. After adding the SxProps
from MUI, I'm encountering the heap error, so I tried to remove it just to check if it's the root cause, and it is.
This may also seem related to the issue when using Zod.
export type CreateComponentProps<T = {}> = T & ComponentTestKit & MuiBaseComponent;
export interface MuiBaseComponent {
className?: string;
sx?: SxProps;
}
Bug Report
🔎 Search Terms
Memory
🕗 Version & Regression Information
After upgrading to 4.3.2 I get a "JavaScript heap out of memory" exception when i try to run
tsc
. Downgrading to 4.2.4 does not yield the same error.🙁 Actual behavior
It crashed.
🙂 Expected behavior
No crash