strapi icon indicating copy to clipboard operation
strapi copied to clipboard

Strapi module edge not working in Nuxt Bridge

Open kadlinobit opened this issue 2 years ago • 9 comments

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

  • Clone repo
  • npm install
  • npm run dev

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.

kadlinobit avatar Dec 31 '21 06:12 kadlinobit

I'm currently facing this same bug. Subscribing.

Ennazk avatar Jan 13 '22 01:01 Ennazk

Same here. Subscribing.

Zielgestalt avatar Jan 13 '22 13:01 Zielgestalt

Having the exact same problem with a fresh Nuxt app.

f0086 avatar Jan 17 '22 10:01 f0086

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

benjamincanac avatar Jan 17 '22 13:01 benjamincanac

@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?

benjamincanac avatar Jan 25 '22 14:01 benjamincanac

@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?

kadlinobit avatar Jan 25 '22 17:01 kadlinobit

@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!

Zielgestalt avatar Jan 26 '22 00:01 Zielgestalt

@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.

larbish avatar Jan 26 '22 08:01 larbish

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.

Zielgestalt avatar Apr 20 '22 22:04 Zielgestalt