Skip to content

Nuxt.js Plugins Order Error Fix

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Nuxt.js Plugins Order Error Fix. We cover key concepts, practical examples, and best practices.

The Problem

[nuxt] [request error] Cannot find plugin 'my-plugin' — it may not be loaded yet.

Nuxt plugins run in a specific order. A plugin that depends on another plugin must be ordered correctly.

Wrong

// plugins/analytics.js
export default defineNuxtPlugin(() => {
  // Tries to use a plugin that has not loaded yet
  const myPlugin = useMyPlugin()
})

Output: plugin fails because useMyPlugin() is not available yet.

Order plugins in nuxt.config.ts:

export default defineNuxtPlugin({
  plugins: [
    '~/plugins/my-plugin',     // Load this first
    '~/plugins/analytics',     // This can depend on my-plugin
  ],
})

Or use dependencies:

// plugins/analytics.js
export default defineNuxtPlugin({
  name: 'analytics',
  dependsOn: ['my-plugin'],
  setup() {
    const myPlugin = useMyPlugin()
    // Now safe to use
  },
})

Expected output: plugins load in the correct order without dependency errors.

Prevention

  • Explicitly order plugins in nuxt.config.ts
  • Use the dependsOn option for explicit dependencies
  • Create a single plugin that aggregates related functionality

Common Mistakes with plugins order

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world NUXTJS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the execution order of Nuxt plugins?

Plugins run in the order specified in nuxt.config.ts. Array plugins run first, then directory-based plugins in alphabetical order.

Can I make a plugin run only on the client or server?

Yes. Add .client.js or .server.js suffix to the plugin file (e.g., plugin.client.js). Plugins without a suffix run on both client and server.

How do I pass options to a Nuxt plugin?

Return an options or provide object from the plugin. Use useNuxtApp().$pluginName to access plugin-provided utilities in components.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro