Samuelreichoer
vitest not working with imports form '#app'
I use vitest for tests and I want to still use '#app' imports like: import { useRuntimeConfig, useRoute, createError, useRequestURL, useFetch } from '#app'
Unfortunately I get this error when running tests
FAIL tests/composables/useCraftQuery.test.ts [ tests/composables/useCraftQuery.test.ts ]
Error: Cannot find module '#app' imported from '/Users/samuel/Documents/b-privat-projekte/a-repos/nuxt-craftcms/src/runtime/composables/useComposables.ts'
❯ src/runtime/composables/useComposables.ts:4:1
2| import { defu } from 'defu'
3| import { getBearerToken, getCurrentSite, getSiteUri } from '../utils/helper'
4| import { useRuntimeConfig, useRoute, createError, useRequestURL, useFetch } from '#app'
| ^
5| import type { UseFetchOptions } from '#app'
6| import { computed, toValue } from '#imports'
Caused by: Error: Failed to load url #app (resolved id: #app) in /Users/samuel/Documents/b-privat-projekte/a-repos/nuxt-craftcms/src/runtime/composables/useComposables.ts. Does the file exist?
❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-BMIURPaQ.js:35688:17
8 replies
Custom Fetch Types not align
I have following custom composable function:
import type { UseFetchOptions } from '#app'
export function useCraftFetch<T>(
url: string | Request | Ref<string | Request> | (() => string | Request),
options: UseFetchOptions<T> = {}
) {
const { authToken } = useRuntimeConfig().public.craftcms
const headers = {
'Authorization': authToken,
}
const customOptions: UseFetchOptions<T> = {
...options,
headers: {
...headers,
...(options.headers || {})
}
}
return useFetch<T>(url, customOptions)
}
And I get a ts error in the useFetch part where customOptions is set. Why is that?
23 replies
Prerendering not working
Hi, I use nuxt with ddev and craft cms. So basically I run ddev npm run dev for starting the dev server -> Nuxt runs in docker on that url http://0.0.0.0:3000 and gets proxied by the nginx server. Therefor I am able to see the frontend on https://craft-nuxt-starter.ddev.site. When using the dev mode or build script I see no error and data fetching from the https://craft-nuxt-starter.ddev.site/v1/api/xxxx works perfectly.
My nuxt config looks like that:
But when I try to generate the site it throws following errors for every page:
The fetch from the prerender hook works but the api calls in the pages to get the data not.
103 replies
Fetch Data server and client side module recommended way
I am building a querybuilder for Craft CMS and I need to somehow make fetches on client and server side. I tried to do that with useFetch like that
But that only works on client side?! I am confused. What is the recommended way to do that? Maybe like that? https://nuxt.com/docs/guide/recipes/custom-usefetch#custom-usefetch
10 replies