nuxt-modules / strapi

Strapi Module for Nuxt
https://strapi.nuxtjs.org
MIT License
622 stars 77 forks source link

Strapi module edge not working in Nuxt Bridge #202

Open kadlinobit opened 2 years ago

kadlinobit commented 2 years ago

Version

@nuxtjs/strapi: @nuxtjs/strapi-edge@^1.0.0-27336403.27afa67 nuxt: @nuxt/bridge-edge@^3.0.0-27338323.1e98259

Reproduction Link

https://github.com/kadlinobit/djspot-fe/tree/nuxt-3-bridge (nuxt-3-bridge branch)

Steps to reproduce

What is Expected?

Nuxt server starts.

What is actually happening?

During build process, there is an error:

Cannot start nuxt:  Cannot access '_require' before initialization                                                                                                                  07:15:59

  at node_modules/@nuxtjs/strapi/dist/module.mjs:9:46
  at Resolver.g [as _require] (node_modules/jiti/dist/jiti.js:1:55111)
  at Resolver.requireModule (node_modules/@nuxt/core-edge/dist/core.js:274:29)
  at ModuleContainer.addModule (node_modules/@nuxt/core-edge/dist/core.js:129:38)
  at node_modules/@nuxt/utils-edge/dist/utils.js:497:61
  at async ModuleContainer.ready (node_modules/@nuxt/core-edge/dist/core.js:45:7)
  at async Nuxt._init (node_modules/@nuxt/core-edge/dist/core.js:346:5)

I have tried putting Strapi module both to nuxt modules (like with the previous version) and to build-modules (as stated in the new version docs), but none of them works.

Ennazk commented 2 years ago

I'm currently facing this same bug. Subscribing.

Zielgestalt commented 2 years ago

Same here. Subscribing.

f0086 commented 2 years ago

Having the exact same problem with a fresh Nuxt app.

benjamincanac commented 2 years ago

@pi0 I reproduced the same error on a fresh nuxt project, would you have an idea where this could come from?

benjamincanac commented 2 years ago

@kadlinobit I just pushed a fix on the dev branch, would you be able to test the latest @nuxtjs/strapi-edge to make sure the compatibility with bridge is fixed?

kadlinobit commented 2 years ago

@benjamincanac Hi, sorry but I've abandoned Strapi in favor of another CMS and completely refactored my Nuxt project already. Any of you guys - @Zielgestalt , @Ennazk , @f0086 - fancies testing the new version?

Zielgestalt commented 2 years ago

@kadlinobit @benjamincanac thanks, the error is gone.

I'm still struggling with top-level 'await' is not allowed is script setup, so I can't really test fetching data. But this is a general problem for me not related with the module. But if somebody knows a solution for this, maybe we could add this to the documentation.

Thanks!

larbish commented 2 years ago

@Zielgestalt Have you try to use the nuxt3 composable useAsyncData ? Don't know if I well understand your problem but maybe it could resolve it.

Zielgestalt commented 2 years ago

useAsyncData is not available in bridge. My problem was that I can't use e.g. fetchUser like described here in the docs: https://strapi.nuxtjs.org/usage#fetchuser I get this error:

Module Error (from ./node_modules/unplugin-vue2-script-setup/node_modules/unplugin/dist/webpack/loaders/transform.js): 
top-level await is not supported in Vue 2

But since I can use useStrapiUser() without await this isn't a problem anymore.