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

Hooks defined via Plugin Object Syntax are not working #337

Closed
Aietes opened this issue Jul 19, 2023 · 4 comments
Closed

Hooks defined via Plugin Object Syntax are not working #337

Aietes opened this issue Jul 19, 2023 · 4 comments
Labels
bug Something isn't working upstream

Comments

@Aietes
Copy link

Aietes commented Jul 19, 2023

Environment


  • Operating System: Darwin
  • Node Version: v18.17.0
  • Nuxt Version: 3.6.3
  • Nitro Version: 2.5.2
  • Package Manager: pnpm@8.6.9
  • Builder: vite
  • User Config: runtimeConfig, typescript, devtools, modules, imports, app
  • Runtime Modules: @nuxtjs/tailwindcss@6.8.0, @nuxt/devtools@0.6.7, @pinia/nuxt@0.4.11
  • Build Modules: -

Reproduction

export default defineNuxtPlugin({
  name: 'my-plugin',
  enforce: 'pre', // or 'post'
  async setup (nuxtApp) {
    // this is the equivalent of a normal functional plugin
  },
  hooks: {
    // You can directly register Nuxt app hooks here
    'app:created'() {
      const nuxtApp = useNuxtApp()
      // 
    }
  }
})

Describe the bug

Hooks in plugins are not firing when defined via object syntax. Minimal example exactly like in documentation is not working. Defining a hook in the setup function of the plugin works.

Additional context

No response

Logs

No response

@Aietes Aietes changed the title Hook defined via Plugin Object Syntax are not working Hooks defined via Plugin Object Syntax are not working Jul 19, 2023
@huang-julien
Copy link
Member

Can you provide a reproduction please ?
I can't reproduce it https://stackblitz.com/edit/nuxt-starter-kblc9k?file=plugins%2Fhook.ts,nuxt.config.ts

@Aietes
Copy link
Author

Aietes commented Jul 19, 2023

I created a clean Nuxt project locally, with no plugins or additional dependencies. As described above, the setup function fires, but the hooks don't. I'm not sure why this is not reproducible on stackblitz, or where this is coming from :(

------------------------------
- Operating System: Darwin
- Node Version:     v18.17.0
- Nuxt Version:     3.6.5
- Nitro Version:    2.5.2
- Package Manager:  pnpm@8.6.9
- Builder:          vite
- User Config:      devtools
- Runtime Modules:  -
- Build Modules:    -
------------------------------

@Aietes
Copy link
Author

Aietes commented Jul 19, 2023

I found a possible reason. After disabling devtools the hooks are working!

export default defineNuxtConfig({
  devtools: { enabled: false },
})

It seem devtools are causing the problem.

@danielroe
Copy link
Member

cc: @antfu

@danielroe danielroe added bug Something isn't working upstream labels Jul 20, 2023
@antfu antfu transferred this issue from nuxt/nuxt Jul 20, 2023
@antfu antfu closed this as completed in ec1c821 Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream
Projects
None yet
Development

No branches or pull requests

3 participants