Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring via .env variables on Nuxt 3 #84

Closed
Lexpeartha opened this issue Aug 6, 2022 · 16 comments
Closed

Configuring via .env variables on Nuxt 3 #84

Lexpeartha opened this issue Aug 6, 2022 · 16 comments
Labels
bug Something isn't working

Comments

@Lexpeartha
Copy link

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

@Lexpeartha Lexpeartha added the bug Something isn't working label Aug 6, 2022
@Baroshem
Copy link
Collaborator

Baroshem commented Aug 6, 2022

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

@Lexpeartha
Copy link
Author

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

@Baroshem
Copy link
Collaborator

Baroshem commented Aug 7, 2022

@Lexpeartha

Could you please create a reproduction repository in Stackblitz? I tried it once again and was not able to reproduce it.

@Lexpeartha
Copy link
Author

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

@Baroshem
Copy link
Collaborator

Baroshem commented Aug 8, 2022

I see.

Thank you for testing it out. I hope the module will work for you kow without any issues.

Happy coding! 😃

@fmarcheski
Copy link

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

@Lexpeartha Lexpeartha reopened this Aug 16, 2022
@Lexpeartha
Copy link
Author

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

@Baroshem
Copy link
Collaborator

@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 :)

@podlebar
Copy link
Contributor

podlebar commented Aug 19, 2022

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

@Lexpeartha
Copy link
Author

Lexpeartha commented Sep 30, 2022

Closing an issue since everything seems to work fine in newer nuxt release candidates 👍🏽
If anybody encounters the issue again, I'll reopen it

@cfab
Copy link

cfab commented Oct 1, 2022

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

@Lexpeartha Lexpeartha reopened this Oct 1, 2022
@Baroshem
Copy link
Collaborator

Baroshem commented Oct 1, 2022

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

@cfab
Copy link

cfab commented Oct 3, 2022

Well, I wouldn't dare... ;-)
Not sure what to modify anyway !
But thanks.

@Baroshem
Copy link
Collaborator

Baroshem commented Oct 3, 2022

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.

@Baroshem
Copy link
Collaborator

Baroshem commented Oct 3, 2022

Should be working now with 1.1.4 version

@Baroshem
Copy link
Collaborator

Baroshem commented Oct 4, 2022

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.

@Baroshem Baroshem closed this as completed Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants