nuxt / bridge

🌉 Experience Nuxt 3 features on existing Nuxt 2 projects
MIT License
271 stars 29 forks source link

useLazyFetch with nitro: false option doesn't work #841

Closed deleteme closed 1 year ago

deleteme commented 1 year ago

Environment

Reproduction

https://github.com/deleteme/nuxt2-starter-with-bridge/tree/repro-use-lazy-fetch-error

This is a fresh Nuxt 2 app with Bridge. The only modification to the nuxt bridge config is nitro: false.

Describe the bug

Calling useLazyFetch in a Nuxt page Vue component's setup() method throws an error about not having $fetch defined.

Additional context

I didn't find any mention of having to define or implement $fetch in the readme or the Bridge docs. I also didn't find anything mentioning not being able to use select composables with only the Nitro server.

Logs

ERROR  [Vue warn]: Error in setup: "ReferenceError: $fetch is not defined"                                          3:52:15 PM

found in

---> <IndexPage> at pages/index.vue
       <Nuxt>
         <.nuxt/layouts/default.vue> at .nuxt/layouts/default.vue
           <Root>
danielroe commented 1 year ago

You're right, this should be documented. The isomorphic $fetch helper and corresponding useLazyFetch composable, which uses $fetch under the hood, rely on Nitro.

wattanx commented 1 year ago

It is already in the latest documentation. https://nuxt.com/docs/bridge/nuxt3-compatible-api#useasync-and-usefetch

pawmanaloto commented 10 months ago

Hello @wattanx @danielroe is there a way to use useFetch with nitro disabled?

wattanx commented 10 months ago

useFetch is not available in Nuxt Bridge. Also, there is no way to use useLazyFetch with nitro: false. Instead, useLazyAsyncData can be used even with nitro: false.