Auto import server utils
Is there any to have
server/utils/**
auto imported in the server side?
I've tried to modify the nuxt config imports.dir as well as creating a custom module that calls addServerImportsDir
but neither seem to have an effect.10 Replies
Nuxt
server/ · Nuxt Directory Structure
The server/ directory is used to register API and server handlers to your application.
Yea I've looked at that, as far as I can tell it doesn't say anything about importing for the utils ddir
You can add more helpers yourself inside the ~/server/utils directory.Does that not auto import for you on the server? seems like ts complains, but the exports are indeed auto-imported
hmm, no it does not auto import, let me try to remove my custom imports dir setting and module and double check
Yea I get a 500 error when trying to use the function exported from a file in my ~/server/utils dir
what kind of file is it?
are you using named exports?
useFetchTime.ts and yes,
export const useFetchTime => ...
check if its in .nuxt/dev/index.mjs
also restart your server if you haven't tried that
because it does work, i just verified it
this is whats in my file
im wonddering if there is some hidden error? I'm not getting anything in build or vscode
you wouldn't use reactive variables or useFetch on the server
that looks like you'd want to put it in ~/composables
and not use it on the server
you could also use a plugin: something like:
then you could use
useNuxtApp().$timedFetch
to do your callsgrr im on a call and working on multiple things and got them mixed up, 1 sec let me get organized real quick lol
yea i just have the dumb apparently. I was putting a client composable in the server utils ... all I can say is its friday...