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

bug: hook functions can only be called from within a prompt #1426

Closed
paul-thebaud opened this issue Jun 19, 2024 · 8 comments
Closed

bug: hook functions can only be called from within a prompt #1426

paul-thebaud opened this issue Jun 19, 2024 · 8 comments

Comments

@paul-thebaud
Copy link

Description

When using inside Stackblitz, input prompt will crash with the following error after user validate its choice for input:
HookError: [Inquirer] Hook functions can only be called from within a prompt

Error does not show inside a "classical" environment. Error does not seems to show for all available prompts (tested select: no error).

Reproduction

Go to this Stackblitz playground, run node index.js inside terminal and validate any answer for the input prompt.

@SBoudrias
Copy link
Owner

That's quite weird. Did you reach out to Stackblitz?

I would assume they're not just running node - even though it looks like it when running node --version. There's something different with the runtime leading to this issue.

@paul-thebaud
Copy link
Author

@SBoudrias, thanks for your quick reply. As stated on the StackBlitz docs, web containers should provide "a native Node.js environment", so maybe this is not an issue on their side. I opened stackblitz/webcontainer-core#1467 in addition to this issue.

@SBoudrias
Copy link
Owner

It could be an issue with their environment support of Node.js async_hooks. It's been a recurring issue this year where support was lacking on platforms like Bun.

Specifically, async_hooks are tricky around timers. And so, core utilities to bind a callback to an async hooks context would be missing or broken in some platforms. Specifically, I think AsyncResource.bind might be either missing or broken in their containers running Node.

Unrelated to this issue, I'm releasing performance improvements to Inquirer's loaders right right now. This will delay the start of animation, which maybe will fix that very specific issue you're running into 🤷🏻 (until you start doing async validation.)

@paul-thebaud
Copy link
Author

Thank you a lot for that complete explication! 🙏
I'll try as soon as it get released!

@paul-thebaud
Copy link
Author

According to this issue stackblitz/webcontainer-core#1169 (comment), you're right about async hooks.

@paul-thebaud
Copy link
Author

@SBoudrias, Stackblitz issue has been closed in favor of already tracked stackblitz/webcontainer-core#1169.

I suggested to leave this issue open so I can check out performance improvements and keep in touch 😉

@paul-thebaud
Copy link
Author

@SBoudrias, I updated dependencies on the Stackblitz reproduction to check @inquirer/core v8.2.3, and error still appear 😕
Is there any workaround?

@SBoudrias
Copy link
Owner

The new inquirer (@inquirer/) are heavily relying on AsyncLocalStorage for everything; it won't work without.

The older API inquirer is larger and less ergonomic, but it works without the hooks. So you could use that instead. This version is in maintenance mode.

dgp1130 added a commit to dgp1130/angular-cli that referenced this issue Nov 22, 2024
Apparently `inquirer` requires `async_hooks` which isn't supported in webcontainers, therefore prompting the user fails. Instead we always fall back to the default option.

See: SBoudrias/Inquirer.js#1426
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

2 participants