Skip to content
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

A package with circular dependency will result in stack overflow #58

Closed
brawaru opened this issue Mar 6, 2023 · 1 comment · Fixed by unjs/jiti#125
Closed

A package with circular dependency will result in stack overflow #58

brawaru opened this issue Mar 6, 2023 · 1 comment · Fixed by unjs/jiti#125

Comments

@brawaru
Copy link

brawaru commented Mar 6, 2023

Environment

Package: c12@​1.1.2.
Node: v16.14.2, v18.14.0.

Reproduction

  1. Import a package (normally or dynamically) that has a circular dependency, inside your configuration file. Example: import-meta-resolve.
  2. Try to load that file.

Describe the bug

JITI gets stuck in recursion until eventually it crashes with ‘Maximum call stack size exceeded’.

Additional context

StackBlitz: https://stackblitz.com/edit/node-fughmd?file=example.config.mjs&view=editor.

This is not reproduceable with JITI alone.

Workaround: make it impossible to analyse import by using expression rather than a literal inside dynamic import statement. For example: import('i' + 'mport-meta-resolve').

Logs

No response

@pi0
Copy link
Member

pi0 commented Mar 6, 2023

Thanks for nice reproduction @brawaru. I have narrowed it down to a specific option of jiti. It only happens when require cache is disabled and we do disable it for jitiOptions in c12 by default in order to support invalidating config reloads.

if

Upstream: unjs/jiti#124

As an alternative workaround, you can use jitiOptions:

const { config } = await loadConfig({
  name: 'example',
  jitiOptions: {
    requireCache: true,
  },
});

https://stackblitz.com/edit/node-i7ljxv?file=example.config.mjs,index.mjs&view=editor

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

Successfully merging a pull request may close this issue.

2 participants