nuxt-modules / algolia

🔎 Algolia module for Nuxt
https://algolia.nuxtjs.org/
MIT License
191 stars 35 forks source link

Failed to run nuxt after installing algolia #80

Closed starladyrie closed 2 years ago

starladyrie commented 2 years ago

Version

@nuxtjs/algolia: 1.1.0 nuxt: "nuxt-edge": latest

Reproduction Link

https://github.com/starladyrie/algolia-bug

Steps to reproduce

  1. Create a new project with Nuxt 2
  2. Migrate to Nuxt Bridge
  3. Install @nuxtjs/algolia, following documentation
  4. Run project

What is Expected?

Project should run normally

What is actually happening?

Algolia is throwing the following error:

Nuxt CLI v3.0.0-rc.6                                                                                                                                                                                               16:45:31
                                                                                                                                                                                                                   16:45:33
  > Local:    http://localhost:3000/ 
  > Network:  http://192.168.31.137:3000/

 FATAL  Cannot read property 'public' of undefined                                                                                                                                                                 16:45:34

  at setup (/C:/Users/marri/Documents/algolia/algolia-bug/node_modules/@nuxtjs/algolia/dist/module.mjs:149:32)
  at ModuleContainer.normalizedModule (/C:/Users/marri/Documents/algolia/algolia-bug/node_modules/@nuxt/kit/dist/index.mjs:607:29)
  at async ModuleContainer.addModule (node_modules\@nuxt\core-edge\dist\core.js:174:20)
  at async ModuleContainer.ready (node_modules\@nuxt\core-edge\dist\core.js:47:5)
  at async Nuxt._init (node_modules\@nuxt\core-edge\dist\core.js:346:5)

 ERROR  Cannot start nuxt:  Cannot read property 'public' of undefined                                                                                                                                             16:45:34  

  at setup (/C:/Users/marri/Documents/algolia/algolia-bug/node_modules/@nuxtjs/algolia/dist/module.mjs:149:32)
  at ModuleContainer.normalizedModule (/C:/Users/marri/Documents/algolia/algolia-bug/node_modules/@nuxt/kit/dist/index.mjs:607:29)
  at async ModuleContainer.addModule (node_modules\@nuxt\core-edge\dist\core.js:174:20)
  at async ModuleContainer.ready (node_modules\@nuxt\core-edge\dist\core.js:47:5)
  at async Nuxt._init (node_modules\@nuxt\core-edge\dist\core.js:346:5)
Baroshem commented 2 years ago

Hey, it seems that you cannot have public runtime registered like this for nuxt-edge.

The module registers the configuration from nuxt.config.ts by using public runtime config. I will check how other modules achieve nuxt edge compatibility for such cases and will get back to you with an answer

starladyrie commented 2 years ago

Got it, thank you so much!!

Baroshem commented 2 years ago

@starladyrie I know what is the reason.

In nuxt-edge public runtime config is accessible in a different way:

nuxt.options.publicRuntimeConfig insteead of nuxt.options.runtimeConfig.public in Nuxt 3.

I will create a pull request with this change and release a 1.1.1 version with this fix for Nuxt 2 this week

starladyrie commented 2 years ago

@Baroshem thank you so much, I'll be waiting for this new release then!!

Baroshem commented 2 years ago

Hey @starladyrie

I tested your reproduction repo with the new 1.1.1 version and it seems to be working correctly :)

image image

Thanks for raising this issue and if you have any questions, do not hesitate to contact me.

Happy coding!

starladyrie commented 2 years ago

@Baroshem I tested in my project and it's no longer throwing that error! Thank you so much for your help 😄