graphiti-api/spraypaint.js

Maximum call stack size exceeded

Opened this issue · 12 comments

Hi,

I have the following error on an empty Nuxt project based on typescript (npx create-nuxt-app . followed by https://typescript.nuxtjs.org/guide/setup.html)

 ERROR  INTERNAL ERROR(undefined,undefined) Maximum call stack size exceeded                                                                                                                                       nuxt:typescript 14:25:58
stack trace:
RangeError: Maximum call stack size exceeded
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43632:33)
    at someTypeRelatedToType (/workspaces/app/node_modules/typescript/lib/typescript.js:44028:35)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43752:34)
    at typeRelatedToEachType (/workspaces/app/node_modules/typescript/lib/typescript.js:44013:35)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43730:34)
    at typeRelatedToSomeType (/workspaces/app/node_modules/typescript/lib/typescript.js:43913:35)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43719:34)
    at eachTypeRelatedToType (/workspaces/app/node_modules/typescript/lib/typescript.js:44040:35)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43715:25)
    at isPropertySymbolTypeRelated (/workspaces/app/node_modules/typescript/lib/typescript.js:44717:28)

This error occurs as soon as I use the decorator @Model()
example: at the moment, I only define the ApplicationRecord like this:

import { SpraypaintBase, Model } from 'spraypaint';

@Model()
export default class ApplicationRecord extends SpraypaintBase {
  static baseUrl = 'http://localhost:3000';
  public static apiNamespace = '/api/v1';
}

If I remove the decorator, no error is raised.

for info:

node@d92271203242:/workspaces/app$ yarn dev
yarn run v1.19.1
$ nuxt -H 0.0.0.0 -p 3001

   ╭───────────────────────────────────────────╮
   │                                           │
   │   Nuxt.js v2.10.2                         │
   │   Running in development mode (spa)       │
   │                                           │
   │   Listening on: http://localhost:3001/    │
   │                                           │
   ╰───────────────────────────────────────────╯

ℹ Preparing project for development                                                                                                                                                                                                14:33:39
ℹ Initial build may take a while                                                                                                                                                                                                   14:33:39
✔ Builder initialized                                                                                                                                                                                                              14:33:40
✔ Nuxt files generated                                                                                                                                                                                                             14:33:40
ℹ Starting type checking service...                                                                                                                                                                                nuxt:typescript 14:33:56
ℹ Using 1 worker with 2048MB memory limit                                                                                                                                                                          nuxt:typescript 14:33:56

✔ Client
  Compiled successfully in 20.55s

 ERROR  INTERNAL ERROR(undefined,undefined) Maximum call stack size exceeded                                                                                                                                       nuxt:typescript 14:34:17
stack trace:
RangeError: Maximum call stack size exceeded
    at getPropertyOfObjectType (/workspaces/app/node_modules/typescript/lib/typescript.js:39024:31)
    at isKnownProperty (/workspaces/app/node_modules/typescript/lib/typescript.js:50819:21)
    at isKnownProperty (/workspaces/app/node_modules/typescript/lib/typescript.js:50828:25)
    at hasCommonProperties (/workspaces/app/node_modules/typescript/lib/typescript.js:45147:21)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43692:58)
    at typeRelatedToSomeType (/workspaces/app/node_modules/typescript/lib/typescript.js:43913:35)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43719:34)
    at eachTypeRelatedToType (/workspaces/app/node_modules/typescript/lib/typescript.js:44040:35)
    at isRelatedTo (/workspaces/app/node_modules/typescript/lib/typescript.js:43715:25)
    at isPropertySymbolTypeRelated (/workspaces/app/node_modules/typescript/lib/typescript.js:44717:28)


ℹ Version: typescript 3.6.4                                                                                                                                                                                        nuxt:typescript 14:34:17
ℹ Time: 15674ms                                                                                                                                                                                                    nuxt:typescript 14:34:17
ℹ Waiting for file changes                                                                                                                                                                                                         14:34:17
ℹ Memory usage: 510 MB (RSS: 621 MB)                                                                                                                                                                                               14:34:17

I believe this is an error with TS >= 3.6. Could you try 3.5 and see if it goes away?

Unfortunately TS makes breaking changes all the time and there's always a little lag before we can upgrade Spraypaint. /cc @wadetandy

I agree with you, it is an error with TS 3.6
Unfortunately, I wasn't able to run nuxt in 3.5. Typescript 3.6 is dependency of @nuxt/typescript-build (v0.3.2)

For some reason, if I add typescript v 3.5.3 into my project's dependencies then Nuxt is not able to build vue files :

yarn run v1.19.1
$ nuxt -H 0.0.0.0 -p 3001

   ╭───────────────────────────────────────────╮
   │                                           │
   │   Nuxt.js v2.10.2                         │
   │   Running in development mode (spa)       │
   │                                           │
   │   Listening on: http://172.17.0.2:3001/   │
   │                                           │
   ╰───────────────────────────────────────────╯

ℹ Preparing project for development                                                                                                                                                                                                16:40:32
ℹ Initial build may take a while                                                                                                                                                                                                   16:40:32
✔ Builder initialized                                                                                                                                                                                                              16:40:32
✔ Nuxt files generated                                                                                                                                                                                                             16:40:33
ℹ Starting type checking service...                                                                                                                                                                                nuxt:typescript 16:41:05
ℹ Using 1 worker with 2048MB memory limit                                                                                                                                                                          nuxt:typescript 16:41:05

✖ Client
  Compiled with some errors in 18.36s

ℹ Type checking in progress...                                                                                                                                                                                     nuxt:typescript 16:41:23

 ERROR  Failed to compile with 1 errors                                                                                                                                                                            friendly-errors 16:41:23

This relative module was not found:                                                                                                                                                                                friendly-errors 16:41:23
                                                                                                                                                                                                                   friendly-errors 16:41:23
* ./index.vue?vue&type=script&lang=ts& in ./pages/index.vue                                                                                                                                                        friendly-errors 16:41:23
ℹ Waiting for file changes                                                                                                                                                                                                         16:41:24
ℹ Memory usage: 445 MB (RSS: 554 MB)                                                                                                                                                                                               16:41:24
ℹ No type errors found                                                                                                                                                                                             nuxt:typescript 16:41:31
ℹ Version: typescript 3.5.3                                                                                                                                                                                        nuxt:typescript 16:41:31
ℹ Time: 26143ms                                                                                                                                                                                                    nuxt:typescript 16:41:31

@wadetandy think we'll be able to deal with this?

I just checked out the spraypaint.js project from github.
I changed the typescript version to 3.6.4
And I get the error when I run the cmd yarn build

At the moment, I don't think we can use spraypaint on a new Nuxt project. I haven't tried on a new vue cli project.
Also typescript 3.7 is coming in the next few days.
So I think we should fix this quickly.

I'm trying to find a solution inside spraypaint.js but I don't really know where to look at. Any Help would be appreciated :)

node@8ffaedc09468:/workspaces/spraypaint.js$ yarn build 
yarn run v1.19.1
$ yarn run clean && yarn test:ci && yarn lint:ci
$ rimraf ./dist ./build ./coverage ./lib ./lib-esm
$ yarn test:all-versions && yarn test:es6-compatibility
$ yarn tav
$ /workspaces/spraypaint.js/node_modules/.bin/tav
-- ok
$ yarn build:es6 && mocha --opts test/es6-compatibility/mocha.opts
$ yarn run tsc -p ./tsconfig.lib.json
$ /workspaces/spraypaint.js/node_modules/.bin/tsc -p ./tsconfig.lib.json
/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:75701
                throw e;
                ^

RangeError: Maximum call stack size exceeded
    at hasCommonProperties (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:37686:35)
    at isRelatedTo (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:36440:58)
    at typeRelatedToSomeType (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:36622:35)
    at isRelatedTo (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:36464:34)
    at eachTypeRelatedToType (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:36744:35)
    at isRelatedTo (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:36460:25)
    at isPropertySymbolTypeRelated (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:37301:28)
    at propertyRelatedTo (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:37341:31)
    at propertiesRelatedTo (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:37442:43)
    at isRelatedTo (/workspaces/spraypaint.js/node_modules/typescript/lib/tsc.js:36476:34)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
node@8ffaedc09468:/workspaces/spraypaint.js$ 

Is there any progress made with this issue? I'm getting the same error within a new NuxtJS project running with Typescript 3.7.4

@wadetandy and I are not entirely sure what changed in TS versions to cause this. We're both running an older version of TS at the moment so we haven't been able to allocate bandwidth towards an upgrade. If anyone wants to take a stab at this I'd be happy to merge.

I really would like spraypaint to be compatible with the last version of typescript.
TS is already in version 3.7.5 and spraypaint can't work with version above 3.5.3

I'll be happy to look at it if someone points me into a direction to look at.
I'm quite lost in front of the error message

Unfortunately we're in the same boat, really unsure what changed in TS to cause this. I know @wadetandy looked briefly but we don't have cycles atm to focus on this. It looks like others are getting the same issue: microsoft/TypeScript#33460

The call stack error seems to be caused by the Diff function in util/omit.ts, because it no longer errors when switched to the code that was commented out (in support of TS 2.8).

Things go deeper though - as once the call stack exceeded error is gone, it doesn't compile.
(trying to figure out why, but my TS skills pale in comparison to @richmolj and @wadetandy - my mind would be blown if only I understood half of it!)

I managed to compile with 3.7 in my own fork by changing some types to any. Obviously, this is wrong, but it might shed some light onto what is needed.
I don't know enough about how to resolve conflicts between SpraypaintBase subclass types when they are created with a decorator etc. (specifically around ValidationErrors<this>)

timkrins#2

Hey, I'm running the latest (experimental) typescript version 3.9.0-dev20200425 and I'm still getting this issue. Is there any update on it?

The call stack error seems to be caused by the Diff function in util/omit.ts, because it no longer errors when switched to the code that was commented out (in support of TS 2.8).

Omit is a native utility type, so that module can be removed altogether. I've got a PR open with support for TypeScript 3.9.7 here: #69