harlan-zw / nuxt-seo

The complete SEO solution for Nuxt.
https://nuxtseo.com
949 stars 56 forks source link

Error when trying to use nuxt module which in turn uses this project. #212

Open meksor opened 3 months ago

meksor commented 3 months ago

Describe the bug

Hiya, we are currently writing a convenience module for our web apps. This module contains some components, some code and some libraries (some are ours, some are projects like this). When writing our module and building the playground in the same repo we encounter no problems. But: when trying to include the module from a release in an external project, nuxt prepare errors with the following message:

 % npm install

> postinstall
> nuxt prepare

 ERROR  [unhandledRejection] Nuxt instance is unavailable!                                                            1:28:30 PM

  at useNuxt (node_modules/@nuxt/kit/dist/index.mjs:32:11)
  at isNuxt2 (node_modules/@nuxt/kit/dist/index.mjs:84:25)
  at installModule (node_modules/@nuxt/kit/dist/index.mjs:2415:16)
  at async setup (node_modules/@nuxtjs/seo/dist/module.mjs:45:7)
  at async normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:2112:17)
  at async installModule (node_modules/@nuxt/kit/dist/index.mjs:2415:95)

This seems to be some problem with calling installModule in another installModule call? Other installModule calls in our module.ts do not fail, but they also do not in turn call installModule again... Any hints or ideas? is this a known issue? should we just install all the sub-packages included here manually?

Reproduction

  1. Create new nuxt module.
  2. Install and include this module in the project.
  3. Add installModule('@nuxtjs/seo'); to module.ts:setup()
  4. Install the module you just built in an external project

System / Nuxt Info

------------------------------
- Operating System: Linux
- Node Version:     v18.17.1
- Nuxt Version:     3.11.1
- CLI Version:      3.11.1
- Nitro Version:    2.9.4
- Package Manager:  npm@9.6.7
- Builder:          -
- User Config:      ssr, devtools, modules, srcDir, scseComponents
- Runtime Modules:  @iiasa/scse-components@0.1.9-seo.4
- Build Modules:    -
------------------------------
harlan-zw commented 3 months ago

This is quite an interesting bug, it is a Nuxt core issue though so out of scope for this package to solve.

If yo can open an issue on the Nuxt repo with a reproduction it would speed this up quite a bit, otherwise will keep open until I have a chance.

meksor commented 3 months ago

Understood, I'll get back to you on that in a bit when I can squeeze it in. Feel free to close this if you feel it is out of place here, thanks!