Nuxt Layer: Composable from layer not found
Following directory structure:
For unknown reason, I can't use
useK8s
in someHandler.get.ts
. Nuxt complains: ERROR [nuxt] [request error] [unhandled] [500] useK8s is not defined
.
Yet my app/.nuxt/imports.d.ts
contains export { useK8s } from '../../k8s/composables/k8s';
6 Replies
(The composable even shows up in the nuxt devtools)
have you tries
import { useK8s } from '~/../k8s/composables/k8s'
in someHandler.get.ts
yeah, that works. But auto-imports should also work.
I just tried moving my composable to a server util - and I can suddenly use it
sometimes
server/utils
can be a good workaround. Or server/plugins
where you could inject some stuff in nitro hooksYup. Had to remember that composables are not usable in api handlers. Confusing when there's a lot of stuff looking like composables in nitro and nuxt 🙈
AFAIK autoimports are for core folders only; you'll have to set up layer imports manually.
I have used the layer config option
components
for auto-importing layer components, but I think maybe the imports
statement is what you want here.
https://nuxt.com/docs/api/nuxt-config#imports
I don't know if it's supposed to be absolute paths or folders... the docs never seem to be clear about this.
In components, you can use aliases, so might be something like: