Chapters
00:00 - Creating Our Register Controller
01:05 - Using Our Register Controller Methods On Our Routes
02:40 - Handling Our Register Form Submission
03:39 - Introducing Actions
05:45 - Completing Our WebRegister Action
07:20 - Injecting & Using Our WebRegister Action
07:56 - Testing Our Registration Flow
Join The Discussion! (4 Comments)
Please sign in or sign up for free to join in on the dicussion.
tdturn2
When changing over routes to:
router.get('/register', [RegisterController, 'show']).as('register.show').use(middleware.guest())
I'm' getting Error: The import "#controllers/auth/register_controller" is not imported dynamically from start/routes.ts. You must use dynamic import to make it reloadable (HMR) with hot-hook.
is my register_controller.ts not setup or registered properly?
I can work around this, but not as clean as your walkthrough
router.get('/register', async (ctx) => { const { default: RegisterController } = await import('#controllers/auth/register_controller') return new RegisterController().show(ctx) }).as('register.show').use(middleware.guest())
Please sign in or sign up for free to reply
tomgobich
Hi tdturn2!
First, your import is valid and will work, it just won't work with hot module reloading (HMR). HMR is enabled by default in newer AdonisJS 6 projects. Rather than fully restarting the application when a change is made in development, HMR enables the single updated spot to be updated on the fly.
AdonisJS uses NodeJS Loader Hooks to perform HMR, and loader hooks require dynamic imports to work and hot-swap modules when updated. If you'd like to read more on this, they walk through the full what & whys in the documentation.
So rather than importing your controller like this, which will not work with HMR:
You can instead dynamically import the controller, which will work with HMR:
If you have your text editor fix lint errors on save, this change will happen automatically when you save your file. You'll see this happen for me in the lesson around the 2:20 mark. If you're using VSCode, you can turn this on by installing the ESLint extension, and then adding the below to your JSON user settings.
Please sign in or sign up for free to reply
tdturn2
Awesome, that was it! Thank you!
Please sign in or sign up for free to reply
tomgobich
Anytime!! 😊
Please sign in or sign up for free to reply