strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Strapi V4 with Nuxt Bridge throws «$fetch is not defined»

Open crazymind opened this issue 3 years ago • 1 comments

Version

    "@nuxtjs/strapi": "^1.3.1",
    "nuxt-edge": "latest",
    "@nuxt/bridge": "npm:@nuxt/bridge-edge",
    "node-fetch": "^3.2.3",
    "ohmyfetch": "^0.4.15",

Reproduction

Upgraded my Nuxt2 App to nuxt Bridge to be able to use Strapi v4. Tried to yarn add node-fetch ohmfetch. No success. Do I need to register the $fetch somehow in Nuxt?

Steps to reproduce

export default {
// ...
  setup() {
    const { login } = useStrapiAuth()
    
    login({
      identifier: '[email protected]',
      password: '12345678',
    })

    return { login }
  },
// ...

What is Expected?

Try to login.

What is actually happening?

Throwing an error: $fetch is not defined Happens also with create, find etc.

crazymind avatar Apr 11 '22 09:04 crazymind

Becuase of this bug in Nuxt Bridge I needed to disable nitro: Build fails with SSR turned off

As I read somewhere nitro implements $fetch. Therefore it makes sense that $fetch is not found. Any Idea how I can implement $fetch manually? I tried to install ohmyfetch and node-fetch – no luck. Also tried to inject $fetch as a plugin – also no luck. Anyone an idea how to fix this?

crazymind avatar Apr 12 '22 00:04 crazymind