I'm making two modules, one which has the other one as an optional dependency specified via moduleDependencies, but for some reason it seems the plugin types are not being processed by nuxt at all, the plugin names don't appear in the 'dependsOn' property, the provides aren't showing up in the NuxtApp interface... I don't know what I am doing wrong, any ideas of what may be the issue?
#Module Plugin not being typed
5 messages · Page 1 of 1 (latest)
Hi @cosmic sapphire. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the knowledge sources, there are several common pitfalls and requirements when working with module plugins, type augmentation, and dependencies in Nuxt 3/4:
-
Type Augmentation for Provided Helpers
If your plugin provides helpers (via theprovidekey), Nuxt should automatically type them foruseNuxtApp()and templates. However, for advanced or cross-module scenarios, you may need to manually augment the types. This is done by declaring the helper in ad.tsfile, for example:// index.d.ts declare module '#app' { interface NuxtApp { $hello(msg: string): string } } declare module 'vue' { interface ComponentCustomProperties { $hello(msg: string): string } } export {}This ensures that TypeScript recognizes your injected properties in both the Nuxt app and Vue components. If you don't do this, TypeScript may treat your injected properties as
unknownor not recognize them at all, especially in IDEs like WebStorm or PhpStorm, which have known issues with global property augmentation [Typing Plugins]. -
Correct Path for Type Imports
There is a known issue where type imports in generated plugin.d.tsfiles use"nuxt/app"instead of"#app", which breaks type augmentation. Manually replacing"nuxt/app"with"#app"in your built module's type files can resolve this, but it's a workaround. The root cause is often related to how your module is built and how Nuxt resolves type augmentation [Plugin types breakNuxtAppInjectionstype].
-
Module Dependencies and Plugin Registration
When usingmoduleDependencies, ensure that:- Your dependent module is properly installed and resolved in the consuming project.
- Plugins are placed in the correct directory (
runtime/app/plugin.tsfor modules). - You are not using
link:in your workspace, as this can cause Nuxt to resolve types from a differentnode_modulesfolder, breaking augmentation. Usefile:or package and install your module as a.tgzfile instead [Plugin types breakNuxtAppInjectionstype].
-
Plugin Names and
dependsOn
For thedependsOnproperty to work, your plugins must have anameproperty. If the plugin name is missing, Nuxt cannot resolve dependencies between plugins. Make sure your plugins are defined like this:export default defineNuxtPlugin({ name: 'my-plugin', provide: { ... }, // ... })Then, in the dependent plugin:
export default defineNuxtPlugin({ name: 'dependent-plugin', dependsOn: ['my-plugin'], // ... })This ensures that the dependency order is respected and that the
dependsOnproperty is recognized [Creating Plugins]. -
TypeScript Configurations
If you are developing a module, ensure yourtsconfig.jsonis set up to extend the correct Nuxt configs, and that your type files are included in the build output. There have been recent changes in how Nuxt handles multipletsconfigfiles for modules, playgrounds, server, and app contexts [Module sub dependencies aliases lost after 3.19.2].
Summary of Troubleshooting Steps:
- Ensure your plugins have a
nameproperty if you usedependsOn. - Manually augment types in a
d.tsfile if automatic typing fails. - Check that your module's type files import from
#app, notnuxt/app. - Avoid using
link:for local module development; usefile:or package the module. - Place plugins in the correct directory (
runtime/app/plugin.tsfor modules). - Double-check your
tsconfig.jsonsetup for both the module and the consuming app.
If after these steps your plugin types still do not appear, it may be due to a bug or an edge case in Nuxt's type resolution, as discussed in the referenced issues. In that case, reviewing the latest Nuxt releases and related GitHub issues for fixes or workarounds is recommended.