algolia
algolia copied to clipboard
Configuring via .env variables on Nuxt 3
Version
@nuxtjs/algolia: 1.1.1 nuxt: 3.0.0-rc.6
Steps to reproduce
- Add Algolia to Nuxt 3 project
- Configure it via
env
variables
What is happening?
algolia: {
applicationId: process.env.ALGOLIA_APP_ID ?? 'applicationId',
apiKey: process.env.ALGOLIA_API_KEY ?? 'apiKey',
},
When starting a project error is thrown Cannot destructure property 'applicationId' of '__vite_ssr_import_0__.useRuntimeConfig(...).algolia' as it is undefined.
Not sure if this has something to do with #81 or #63 but considering the example in the playground, this should work
Hey @Lexpeartha
Could you try to rebuild your project or and remove node modules?
I am using env variables in module repo, demo projects, tutorials, and many more so this issue seems wuite strange
I was running nuxt 3 edge version, but down-graded it to rc 6 and issue was still there I did delete both node_modules and .nuxt, but it didn't do anything
@Lexpeartha
Could you please create a reproduction repository in Stackblitz? I tried it once again and was not able to reproduce it.
Well... I can't reproduce it now since it started working for my project as well 🤷🏽♂️ Idrk what that was, but it seems to work alright now, thanks
I see.
Thank you for testing it out. I hope the module will work for you kow without any issues.
Happy coding! 😃
I am seeing this issue on 1.1.1. When I roll back to 1.1.0, it works fine.
Running Nuxt 3.0.0-rc.8
@Baroshem Not sure what might be causing the problem to appear again, but it would be great if you could update @nuxt/kit
dependency since nuxt 3 in newer releases migrated to vite 3, so that might have some impact?
@Lexpeartha @fmarcheski
Yes, the update to the newest version of nuxt and nuxt/ki is a planned feature. I want to release it next week preferably with #83 as a 1.2.0. I just need to test some things out to not cause breaking changes for your projects :)
@Baroshem I can confirm this bug.. the solution is to move the algolia config to runtimeConfig.public
. If you don't have any public runtimeConfig it works fine as described in the docs.
Works:
export default defineNuxtConfig({
modules: ['@nuxtjs/algolia'],
runtimeConfig: {
FOO: process.env.FOO,
public: {
algolia: {
apiKey: "12345678",
applicationId: "123",
instantSearch: true
},
}
},
algolia: {
apiKey: "12345678",
applicationId: "123",
instantSearch: true
},
})
Fails:
export default defineNuxtConfig({
modules: ['@nuxtjs/algolia'],
runtimeConfig: {
FOO: process.env.FOO,
public: {
anyKey: '123'
}
},
algolia: {
apiKey: "12345678",
applicationId: "123",
instantSearch: true
},
})
The Bug seems to be that if you define a public runtime there is no merge from the Algolia config and the general public runtime config. Not sure if this is a Nuxt Bug or from this Module. But i guess it's on Nuxt side as a downgrade to a earlier release fixes the issue.
Closing an issue since everything seems to work fine in newer nuxt release candidates 👍🏽 If anybody encounters the issue again, I'll reopen it
I still have the error on RC 11 after having destroyed node_modules and .nuxt... [nuxt] [request error] [unhandled] [500] Cannot destructure property 'applicationId' of 'vite_ssr_import_0.useRuntimeConfig(...).algolia' as it is undefined.
but it worked if I duplicate algolia config object in runtimeConfig.public
@cfab
I would say then that this issue may be caused by the Nuxt itself rather than the module but I will investigate on my side. Have you tried modifying the module code in node_modules to see if it makes a difference?
Well, I wouldn't dare... ;-) Not sure what to modify anyway ! But thanks.
Folks,
The issue is caused when you have both algolia object and runtimeConfig.public both registered in nuxt.config.ts file.
I will release a fix today to fix this issue.
Should be working now with 1.1.4 version
Guys, I am closing the issue as it was tested already in a few Nuxf 3 apps with public runtime config. If this error occurs again, please reopen.