{"id":16266236,"url":"https://github.com/dulnan/nuxt-plugin-order","last_synced_at":"2026-05-19T19:11:13.894Z","repository":{"id":230009775,"uuid":"778171906","full_name":"dulnan/nuxt-plugin-order","owner":"dulnan","description":"A small build module for Nuxt 3 to enforce a specific order of plugins at build time.","archived":false,"fork":false,"pushed_at":"2024-03-27T09:11:11.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T16:02:44.702Z","etag":null,"topics":["nuxt","nuxt-module","nuxt-plugin","plugins"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nuxt-plugin-order","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dulnan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-27T08:08:57.000Z","updated_at":"2024-03-27T09:16:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"86f9b65f-37c8-40e0-a3a2-3d03e95d18cc","html_url":"https://github.com/dulnan/nuxt-plugin-order","commit_stats":null,"previous_names":["dulnan/nuxt-plugin-order"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Fnuxt-plugin-order","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Fnuxt-plugin-order/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Fnuxt-plugin-order/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dulnan%2Fnuxt-plugin-order/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dulnan","download_url":"https://codeload.github.com/dulnan/nuxt-plugin-order/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247865276,"owners_count":21009228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nuxt","nuxt-module","nuxt-plugin","plugins"],"created_at":"2024-10-10T17:40:23.721Z","updated_at":"2026-05-19T19:11:13.864Z","avatar_url":"https://github.com/dulnan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nuxt-plugin-order\n\nA small build module for Nuxt 3 to enforce a specific order of plugins at build\ntime.\n\n## Setup\n\n### Install module\n\n```\nnpm install --save nuxt-plugin-order\n```\n\n### Configuration\n\n```typescript\nexport default defineNuxtConfig({\n  modules: ['nuxt-plugin-order'],\n\n  pluginOrder: {\n    order: [\n      // Match plugins by their file path.\n      // Note that only a single plugin may match.\n      // The match is performed as \"plugin.src.includes(v.pathMatch)\".\n      { pathMatch: 'pinia.mjs' },\n\n      // Local plugin provided by your app.\n      { pathMatch: 'initData.ts' },\n    ],\n    logSortedPlugins: true,\n  },\n})\n```\n\n## The problem\n\n```typescript\nexport default defineNuxtPlugin(() =\u003e {\n  const user = useUserStore()\n  // \"getActivePinia()\" was called but there was no active Pinia.\n})\n```\n\nBecause you tried to use Pinia while it was not yet injected.\n\n```typescript\nexport default defineNuxtPlugin(() =\u003e {\n  const { $api } = useNuxtApp()\n  await $api.loadSiteData()\n  // Cannot read properties of undefined (reading 'loadSiteData')\n})\n```\n\nBecause you tried to use something provided by a plugin from an installed\ndependency or one of your own plugins.\n\nA classic example is something like this:\n\n- Plugin A: Coming from a module that injects a global $api object\n- Plugin B: A local plugin that adds a\n  `$api.beforeRequest((request) =\u003e { request.headers.token = getUserToken() })`\n  callback\n- Plugin C: A local plugin that calls `$api.loadData()`\n\nIn this case, if plugin C is initialized _after_ plugin B, then the request made\nby plugin C is missing the `beforeRequest` callback and its request will not\ncontain the authentication token header. We need an explicit order here.\n\nCurrently it's not possible to always enforce a specifc order of plugins. While\nit's possible to define dependencies and a specific numeric order for custom\nplugins (using the `dependsOn`, `order` or `enforce` properties in\n`defineNuxtPlugin`), this may not always work when using plugins provided from\nthird party modules or layers.\n\nIn addition, a small change in a dependency could have a breaking impact on how\nyour app works: If such a module provided plugin changes its order after\nupdating dependencies, it could result in unexpected runtime behaviour.\n\nThis module is a small helper to enforce an explicit order of plugins at build\ntime, that is deterministic.\n\n## How it works\n\nThe module requires that all plugins in your app have exactly **one** entry in\nthe `order` configuration, **except for**:\n\n- plugins that contain \"node_modules/nuxt\" in their path\n- plugins that contain \"node_modules/@nuxt\" in their path\n- the plugin that contains \"components.plugin.mjs\" in its path\n\nYou can still add an `order` entry for any of these, but in general the order of\nplugins that are provided by Nuxt itself is correct and very likely not the\ncause of your problems.\n\nIf the module finds a plugin for which it can't determine an exact weight, it\nwill throw an error.\n\nThe final weight is determined as such:\n\n- The initial weight is calculated based on the initial order as determined by\n  Nuxt itself\n- For plugins that are defined in `order`, their weight is calculated as\n  `1000 + index_inside_order`\n- The final weights are then sorted from _lowest to highest_.\n\nBy default, the module will then log the final order of all plugins to the\nconsole. This can be disabled by setting `logSortedPlugins: false`.\n\n## Should I use this?\n\nShort answer: Probably not.\n\nLong answer: It depends. If you have complex dependencies of several plugins\ncoming from different packages, layers, etc., then enforcing a strict order at\nthis level might be very helpful and prevent potential bugs. But if you only\nhave local plugins, then you can already enforce a specific order by giving all\nyour plugins a name and then use `dependsOn` to let Nuxt determine the correct\norder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdulnan%2Fnuxt-plugin-order","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdulnan%2Fnuxt-plugin-order","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdulnan%2Fnuxt-plugin-order/lists"}