Skip to content

RangeError: Maximum call stack size exceeded #246

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
kferrone opened this issue Sep 18, 2018 · 17 comments
Closed

RangeError: Maximum call stack size exceeded #246

kferrone opened this issue Sep 18, 2018 · 17 comments

Comments

@kferrone
Copy link

I unfortunately get the following error a lot when I use this package.

RangeError: Maximum call stack size exceeded

The title of the error is always the same but the rest of the stack trace seems to be pretty random depending on where it failed and what type it was run for.

Here is a link to my sampler project which shows off my problems:
@kferrone/sequel_fun

So far I have only had issues with anything related to Sequelize which may help narrow the problem. I've tried the same scenarios on other Interfaces from Elasticsearch, Restify, Winston, etc... and they all worked.

Do you see anything you know would trip this out? Any ideas on how to get it to generate correctly?

Some things I tried:

  • Setting the stack size like so --stack-size=5000, however that just gives me a stack fault and quits no matter whatI do.
  • Tried directly generating a schema from another Interface I never used, i.e. ISequelizeUriConfig, still the same issue, which at least shows it's not what I have done causing the issues.
  • step through debugging was too complicated . . .
  • tried a lot of combinations of the available cli args, i.e. topRef, aliasRef, etc. . .
@domoritz
Copy link
Collaborator

Hmm, maybe it's because Sequelize has a lot of dependencies. Or it could be a bug in this tool.

@awinograd
Copy link

I am also seeing this error:

/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:755
                    this.getDefinitionForRootType(typ, reffedType, definition);                     
                         ^

angeError: Maximum call stack size exceeded
    at JsonSchemaGenerator.getTypeDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:755:26)                                                 
    at JsonSchemaGenerator.getUnionDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:444:32)                                                
    at JsonSchemaGenerator.getTypeDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:726:26)                                                 
    at JsonSchemaGenerator.getDefinitionForRootType (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:295:45)                                          
    at JsonSchemaGenerator.getTypeDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:755:26)                                                 
    at JsonSchemaGenerator.getUnionDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:444:32)                                                
    at JsonSchemaGenerator.getTypeDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:726:26)                                                 
    at JsonSchemaGenerator.getDefinitionForRootType (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:295:45)                                          
    at JsonSchemaGenerator.getTypeDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:755:26)                                                 
    at JsonSchemaGenerator.getUnionDefinition (/Users/awinograd/.config/yarn/global/node_modules/typescript-json-schema/typescript-json-schema.js:444:32) 

My project unfortunately isn't open sourced so I can't share the code here. It uses a fair number of node modules but not Sequelize

@domoritz
Copy link
Collaborator

@awinograd, you might be able to increase the stack size to fix this.

@awinograd
Copy link

@domoritz,

running typescript-json-schema --stack-size=100000 tsconfig.json "*" still results in a max stack error.

I'm trying to debug / understand the code. Hopefully I can figure out something interesting. If there's anything/information you think could be helpful, please let me know.

@awinograd
Copy link

It appears that unionType.aliasSymbol.escapedName === 'ReactNode' in getUnionDefinition when seeing the stack overflow

@domoritz
Copy link
Collaborator

Can you give https://github.com/vega/ts-json-schema-generator a try? I'm actively adding features to that version while here I mostly help fix bugs.

@awinograd
Copy link

Yep, sure thing @domoritz.

Digging further on my end it looks like there's a recursive type definition for react

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b50d5f10f329fddde8267918bb8e1508d7ce21cc/types/react/index.d.ts#L150-L152

If I change ReactNodeArray to extends Array<any> the program makes it to a max callstack crash at a later point.

@domoritz
Copy link
Collaborator

Interesting. We should be able to support recursive types (see

if (asRef) { // must be here to prevent recursivity problems
for example) but we are probably missing a case somewhere.

@awinograd
Copy link

Thanks for explaining that behavior. I'll try to investigate that logic to see why this case is slipping through

RE ts-json-schema-generator i'm having a little bit of trouble getting it running. It doesn't appear to be pulling in types properly and is additionally asking for the --jsx flag in a warning which it doesn't seem to allow in the cli options

@domoritz
Copy link
Collaborator

Hmm, the jsx is an option you add to your tsconfig. See https://github.com/vega/vega-lite/blob/955272b94b5d459e7538ff78075df9b32b9a6756/package.json#L44 for an example in my large TS project.

@awinograd
Copy link

ok, i had to pass my tsconfig as path to get that working.

Still having some issues with the react typedefs but no longer a stack overflow

UnknownNodeError: Unknown node "AccessibilityPropsIOS" (ts.SyntaxKind = 163) at /Users/awinograd/programming/RNHellowWorld/node_modules/@types/react-native/index.d.ts(1835,71) 

Worth opening an issue over there?

@domoritz
Copy link
Collaborator

Hmm, that error happens when I didn't implement a particular node type. I won't have type to look into this until March but you could submit an issue and maybe look into a PR.

@awinograd
Copy link

Ok, thanks for all of your help @domoritz.

I'll get some issues with reproduction repos filed sometime today.

@max-leuthaeuser
Copy link

Is there any progress?
Current version is still failing with the mentioned call stack size exceeded.
(e.g. tried it on DefinitelyTyped/types/react/index.d.ts)

@domoritz
Copy link
Collaborator

domoritz commented Sep 5, 2019

I'd recommend using https://github.com/vega/ts-json-schema-generator instead since I don't have the cycles to woke on new features for this library.

@visormatt
Copy link

This seems to be triggered when a component is using a React.Xxxx typing in the components interface 🤔 My guess is that these are too complex and filled with overloads and things just blow up. In my current use-case it's React.ReactNode and manually setting a type-annotation for that field seems to avoid this. Now to figure out how to handle this new field 🤷

Ex: this will blow up

interface ExComponentProps {
  cta: React.ReactNode;

  // ... all the others as normal
}

This gets us around the issue

interface ExComponentProps {
  /**
   * @TJS-type Library
   */
  cta: React.ReactNode;

  // ... all the others as normal
}

@domoritz
Copy link
Collaborator

Fixed in #383

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

5 participants