wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc
MIT License
496 stars 32 forks source link

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

Open domoritz opened 4 years ago

domoritz commented 4 years ago

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.

wessberg commented 4 years ago

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.

domoritz commented 4 years ago

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.

wessberg commented 4 years ago

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? :-)

domoritz commented 4 years ago

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

wessberg commented 4 years ago

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

wessberg commented 4 years ago

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.

domoritz commented 4 years ago

Awesome!

lolleko commented 3 years ago

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

ghost commented 3 years ago

Any updates?

darklight9811 commented 3 years ago

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

archfz commented 2 years ago

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?

AndriiSherman commented 1 year ago

+1