question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`addPlugin` from `@nuxt/kit` prepends plugins

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.4
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: modules
  • Runtime Modules: @/modules/pinia, @/modules/my-module
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-ba6rwp?file=nuxt.config.ts

Describe the bug

addPlugin, by default, prepends to the list of plugins. This is great for the purpose described in code comment.

There are two problems though:

a) a module depends on other modules, the natural approach is to order them in a manner that dependencies are first

modules: [
  '@pinia/nuxt', 
  'my-module-depends-on-pinia' // <-- uses pinia
]

b) a module can expose more than one plugin depending on each other

addPlugin(resolver.resolve('./plugins/api.js')
addPlugin(resolver.resolve('./plugins/auth.js') // <-- calls api

In both cases, the module / plugin registered later does not have access to the plugins added prior. Adding { append: true } is not ideal, as it puts the module plugins after user plugins.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pi0commented, Aug 8, 2022

Hi @Aareksio These two are not related with the built-in app:created hook and plugin ordering.

Closing this issue because default preprend behavior is intended explained in previous comment.

0reactions
Aareksiocommented, Aug 8, 2022

Linking here as discussions tend to be overlooked and it is heavily related: https://github.com/nuxt/framework/discussions/6436

Read more comments on GitHub >

github_iconTop Results From Across the Web

r/Nuxt - Why does this.addPlugin prepend the plugin instead ...
Hey Nuxt addicts, I have a quick question regarding Nuxt plugins. I recently found out that Nuxt actually does not push a plugin...
Read more >
The ModuleContainer class - Nuxt
Registers a plugin using addTemplate and prepends it it to plugins[] array. this.addPlugin({ src: path.resolve(__dirname, 'templates/foo.js'), ...
Read more >
Add plugin's plugin dependency as plugin dependency of user
I am creating an SBT plugin to be used in all Scala projects in my company. It is a collection of commonly used...
Read more >
using ___NODE is deprecated - Strapi/Gatsby-Source-Strapi
Issue Title Created Date Comment Count Updated D... what would a unique component thingy look like 11 2022‑08‑01 2022‑08‑26 API not respond well with 404...
Read more >
sbt Reference Manual — Using plugins
Enabling and disabling auto plugins. A plugin can declare that its settings be automatically added to the build definition, in which case you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found