-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Preloads not being loaded during ace command execution #4858
Comments
Its because you have not started the app. The app must be started in order for all lifecycle actions to happen (including preloading files). static options: CommandOptions = {
startApp: true,
} |
You're right, I've forgotten to copy that to the reproduction repo, but my actual app had this. Configured reproduction console command to start the app, issue is still there. |
@thetutlage can you reopen? I believe issue is valid. |
That's odd, because I have just tried in the online code sandbox and it still gives me an error: But once I uncomment fix in the the bin/console.ts, it starts working as expected: Have you tested in your local env? Online sandbox is at node 20, could it relate somehow? (p.s. my local env is at 22, and have same issue) Can I provide any other info to help you reproduce? |
Yes, I tried it locally and it seems to work fine for me. I am also using Node v22. Can you try updating all the dependencies? |
No luck, still same issue both locally and in online sandbox. Updated to the latest versions:
Just for the record, here is the list of updated deps:
Will try to investigate further this week. |
Super weird. Because the same code works flawlessly on my end. Finally, can you please run your code with |
Package version
@adonisjs/[email protected]
Describe the bug
Preloads and/or validator macros are not loaded in ace commands lifecycle.
Reproduction repo: https://codesandbox.io/p/github/qodeboy/adonis-ace-validator-bug/main
Steps:
node ace
, you will get aTypeError: vine.string(...).regex(...).assume is not a function
error.#bin/console.ts
and uncomment workaround (import start/validator
)node ace
- now executes without an error.Implementation notes:
Breakdown:
Sometimes we need to use a validator (will all extension/macros we configured) outside of HTTP context. Valid use cases is validation in ace commands or background/queue jobs. But the issue is that macros registered using preload is not being picked up when app is started in ace context.
This results in runtime errors when trying to use shared validator which use macros/extensions. Current workaround is to manually import validator preload inside
bin/console
file, but this feels dirty.Solutions I have tried:
Questions:
Reproduction repo
https://codesandbox.io/p/github/qodeboy/adonis-ace-validator-bug/main
The text was updated successfully, but these errors were encountered: