#36422·nuxt

Allow modules to register directories for the keyed-function factory scan (createUseFetch / createUseAsyncData)

Author: planitronCreated Sep 27, 2026Updated Sep 28, 2026

Describe the feature

createUseFetch and createUseAsyncData factories are only detected when they live in <layer>/composables. The compiler scan (runScanPlugins in packages/nuxt/src/compiler/module.ts) iterates over nuxt.options._layers and resolves resolve(layer.config.srcDir, 'composables'). Composables exposed by a module through addImportsDir() are auto-imported, but never scanned. A factory defined in a module is therefore not transformed, and gets no automatic key.

Our setup: a shared Nuxt module used by several sites exposes a useAPI composable that wraps useFetch with a custom $fetch. Following the "Custom useFetch" recipe, we would like to write it with createUseFetch, but this only works if the module is turned into a layer.

Proposal

A way for modules to add scan directories. For example, a compiler.scanDirs option that modules can push to, or a kit helper such as addCompilerScanDir(path).

Current workaround

A manual wrapper around useFetch, or registering the name in optimization.keyedComposables. Both work, but lose the benefit of the factory.

Additional information

Checked against v4.5.2.