feat: warn on misconfigured NUXT_PUBLIC_SCRIPTS_* env vars#778
Conversation
Nuxt resolves env vars against runtimeConfig before modules run, so a mistyped `NUXT_PUBLIC_SCRIPTS_*` key (e.g. using a marketing name like `MICROSOFT_CLARITY` instead of the registry key `CLARITY`) is silently dropped and the script loads with an empty option. Add a build-time scan over `process.env` that warns when an env var with the public scripts prefix can't be resolved: unknown registry key (with a suggested correction), unknown field on a valid key (listing valid fields), or a valid key whose script isn't registered.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds validation for Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔗 Linked issue
Resolves #769
❓ Type of change
📚 Description
Nuxt resolves env vars against
runtimeConfigbefore modules run, so a mistypedNUXT_PUBLIC_SCRIPTS_*key (e.g. the marketing nameNUXT_PUBLIC_SCRIPTS_MICROSOFT_CLARITY_IDinstead of the registry keyNUXT_PUBLIC_SCRIPTS_CLARITY_ID) gets silently dropped and the script loads with an empty option. This is what bit the reporter in #769, and it's a class of error that will keep happening.Adds a build-time scan over
process.envthat warns when aNUXT_PUBLIC_SCRIPTS_*var can't be resolved, with three cases:MICROSOFT_CLARITY_ID→Did you mean \NUXT_PUBLIC_SCRIPTS_CLARITY_ID` (registry key `clarity`)?`CLARITY_FOO→ lists the valid fields forclarity.scripts.registry, so the value won't be consumed. Suggests addingregistry: { <key>: {} }.Supersedes #774, which only documented the Clarity case; this catches it (and the same mistake on every other script) at build time.