Nuxt Site Config not working in combination with Nuxt Turnstile
Applelo opened this issue · comments
🐛 The bug
Since Nuxt 3.12, Nuxt Turnstile is causing bugs across my website with two modules.
The first one, nuxt-multi-cache was easy to fix, I had just to change the position of the modules inside the nuxt.config.ts file.
The second one, @nuxtjs/sitemap throws an error when I load the website.
ERROR [nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading 'debug')
at Object.handler (./node_modules/.pnpm/nuxt-site-config@2.2.12_@nuxt+devtools@1.3.3_cc2uo6sas5d5jmayayiogvdkxu__@unocss+webpack@0.60_fse6xbdnt3mfht7ixfkdoaxcgy/node_modules/nuxt-site-config/dist/runtime/nitro/middleware/init.mjs:12:19)
at ./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:31
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.callAsync (./node_modules/.pnpm/unctx@2.3.1/node_modules/unctx/dist/index.mjs:72:16)
at async Server.toNodeHandle (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:7)
If I remove the Nuxt Turnstile module, Nuxt sitemap is working as expected.
🛠️ To reproduce
https://stackblitz.com/edit/nuxt-starter-dj2rf9?file=nuxt.config.ts
🌈 Expected behaviour
To not making other modules crash :)
ℹ️ Additional context
- Operating System: Darwin
- Node Version: v20.14.0
- Nuxt Version: 3.12.1
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: pnpm@9.3.0
- Builder: -
- User Config: modules, sitemap, delayHydration, turnstile, security, routeRules, imports, multiCache, graphqlMiddleware, runtimeConfig, nitro, i18n, piniaPersistedstate, experimental, image, prismic, vite
- Runtime Modules: @nuxtjs/sitemap@5.2.0, @vueuse/nuxt@10.11.0, @pinia/nuxt@0.5.1, @pinia-plugin-persistedstate/nuxt@1.2.0, @nuxtjs/i18n@8.3.1, @vee-validate/nuxt@4.13.1, @nuxtjs/prismic@3.2.1, nuxt-security@1.4.3, @nuxt/image@1.7.0, nuxt-graphql-middleware@4.0.0, nuxt-multi-cache@3.1.1, nuxt-delay-hydration@1.3.3, @nuxtjs/fontaine@0.4.2, nuxt-better-optimize-deps@0.1.0
- Build Modules: -
[EDIT] After investigation, nuxt-site-config-inject this kind of payload
{ stack:
[ { _context: 'system', _priority: -15, name: 'julbo', env: 'development' },
{ _context: 'package.json', _priority: -10, name: 'julbo' },
{ _context: 'buildEnv', _priority: -1, url: 'http://localhost:3000' },
{ _context: '@nuxtjs/i18n', url: 'http://localhost:3000' } ],
version: '2.2.12',
debug: false }
And nuxt turnstile rewrite it somehow and remove all information on nuxt-site-config
object.
[EDIT 2] Seems like the following lines are causing the issue by overwriting stack. https://github.com/nuxt-modules/turnstile/blob/2b425eec7c99ff4cd04021cc3dff8dbd499f44a9/src/module.ts#L67C4-L76C7
[HS EDIT] Another issue I found, we need to put on runtimeConfig the .env infos. It was not necessary before Nuxt 3.12. Related to #27117 ?
{
turnstile: {
secretKey: '',
},
public: {
turnstile: {
siteKey: '',
},
}
}
I have change this
nuxt.options.runtimeConfig = defu(nuxt.options.runtimeConfig, {
turnstile: {
secretKey: options.secretKey,
},
public: {
turnstile: {
siteKey,
},
},
})
to this
nuxt.options.runtimeConfig.turnstile = defu(nuxt.options.runtimeConfig.turnstile, {
secretKey: options.secretKey,
});
nuxt.options.runtimeConfig.public.turnstile = defu(nuxt.options.runtimeConfig.public.turnstile, {
siteKey,
});
I will make a PR to fix this issue.
Here a patch file waiting for the fix to be release on the next version of nuxt.
I believe this issue should be resolved in nuxt/nuxt#27596. Would you check with the nightly release channel? 🙏
Yeah it solves the issue. Thanks, I close the PR and I will close this issue when the next version is release with the fix 😉
Great! It should be out this weekend 🤞
Is out and I can confirm this resolves the issue. @Applelo I hope you can agree? 🙌
Yeah it is working as expected 😄 Thanks for your reactivity 🚀
Not at all - and sorry for the pain 🙏