rollup-plugin-ts icon indicating copy to clipboard operation
rollup-plugin-ts copied to clipboard

[!] (plugin Typescript) RangeError: Maximum call stack size exceeded

Open domoritz opened this issue 4 years ago • 12 comments

  • Version: 1.3.4
  • Rollup Version: 2.26.10
  • Operating System and version (if applicable): macOS
  • Node Version (if applicable): 14.9.0
  • Does it work with tsc (if applicable): yes

Reproduction

Happening with https://github.com/vega/vega-lite/tree/0889ccc6a33a789f985ce0fb08f11f087a245ee4.

Expected Behavior

I expect to get a compiled bundle.

Actual Behavior

$ yarn build
yarn run v1.22.5
$ yarn build:only
$ rollup -c

src/index.ts → build/vega-lite.module.js...
(!) Circular dependencies
src/channeldef.ts -> src/bin.ts -> src/channeldef.ts
src/compile/common.ts -> src/channeldef.ts -> src/compile/common.ts
src/channeldef.ts -> src/compile/format.ts -> src/channeldef.ts
...and 43 more
[!] (plugin Typescript) RangeError: Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at Object.includeSourceFile (/Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/module-merger.ts:117:21)
    at visitImportSpecifier (/Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/visitor/visit-import-specifier.ts:23:34)
    at visitNode (/Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/visitor/visit-node.ts:26:11)
    at /Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/module-merger.ts:40:8
    at visitNodes (/Users/dominik/Code/vega-lite/node_modules/typescript/lib/typescript.js:78371:48)
    at Object.visitEachChild (/Users/dominik/Code/vega-lite/node_modules/typescript/lib/typescript.js:78740:57)
    at Object.childContinuation (/Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/module-merger.ts:36:16)
    at visitNode (/Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/visitor/visit-node.ts:30:19)
    at /Users/dominik/Code/vega-lite/node_modules/@wessberg/rollup-plugin-ts/src/service/transformer/declaration-bundler/transformers/module-merger/module-merger.ts:40:8
    at visitNode (/Users/dominik/Code/vega-lite/node_modules/typescript/lib/typescript.js:78318:23)

Are the circular dependencies a problem here?

Note that compiling this code with rollup hasn't been a problem in the past. I used to compile typescript -> javascript and then use rollup to bundle the generated files.

domoritz avatar Sep 07 '20 02:09 domoritz

Hey there. Circular dependencies shouldn't be a problem, and in fact I have some passing tests for circular dependencies already. But yeah, it does look like something to do with circular deps. Thanks for spotting this. I would greatly appreciate it if you could narrow this down into a minimal repro that I can set up a simple test case for, as that will make it a lot easier for me track this down. In any case I'll see if I can make sense of it by cloning your repo and debugging a bit.

wessberg avatar Sep 09 '20 18:09 wessberg

Thanks for looking into this. For now, I switched to a combination of rollup-plugin-typescript2 and babel in https://github.com/vega/vega-lite/pull/6852/files#diff-ff6e5f22a9c7e66987b19c0199636480. However, since I use your plugin in https://github.com/vega/vega-embed/blob/master/rollup.config.js, https://github.com/vega/vega-tooltip/blob/master/rollup.config.js, and https://github.com/vega/vega-themes/blob/master/rollup.config.js, it would be great to switch to your bundler for Vega-Lite as well.

Since the traceback shows declaration-bundler, I guess this problem may be related to declaration bundling. I'm having some separate issues with declaration bundles (https://github.com/wessberg/rollup-plugin-ts/issues/117) and wonder whether I am doing something wrong that causes these two issues.

domoritz avatar Sep 09 '20 18:09 domoritz

I won't be able to investigate it based on your repro if there is no active branch or PR on which the error is reproducible using @wessberg/rollup-plugin-ts. Is there a way for you to either push a new branch to git based on the state before your last commit or, preferably, prepare a smaller repro (in case you have one) so that I can investigate? :-)

wessberg avatar Sep 09 '20 18:09 wessberg

I made https://github.com/vega/vega-lite/pull/6859 for you. Does that work?

domoritz avatar Sep 09 '20 19:09 domoritz

Yes, that looks good. Thanks, I'll look into it!

wessberg avatar Sep 09 '20 19:09 wessberg

Thanks to your repo, I've managed to reproduce the problem. Feel free to close the PR now, since I have what I need and have prepared a test case. I'll fix it as soon as possible.

wessberg avatar Sep 09 '20 22:09 wessberg

Awesome!

domoritz avatar Sep 09 '20 23:09 domoritz

Encountering the same issue on latest version (1.4.0), any update on this?

lolleko avatar Jun 22 '21 11:06 lolleko

Any updates?

ghost avatar Jul 22 '21 13:07 ghost

@wessberg this is still occuring and I'm trying to make sense out of this, but the deeper I look, the weirder it gets

darklight9811 avatar Sep 06 '21 22:09 darklight9811

I also have this issue. This is only reproducing for commonjs output format. But I suppose that is because of esm + preserveModules declarations aren't merged. On 1.2.27 it doesn't reproduce. Is it possible to merge declarations even in preserveModules?

archfz avatar Mar 26 '22 19:03 archfz

+1

AndriiSherman avatar Aug 04 '23 17:08 AndriiSherman