Nuxt's runtimeConfig - The most common mistake
Вставка
- Опубліковано 25 лип 2024
- 🤯 Throughout my projects, consultancies and code reviews I came across lots of interesting findings - also with regards to Nuxt's runtimeConfig feature. Repeatedly I noticed ONE big mistake though which you might do at this very moment in your project. In this video, explain what it is, why you shouldn't do it and how to use runtimeConfig correctly.
Key points:
👀 The most common runtimeConfig mistake
🔍 Why it will break during runtime
✅ How to resolve the issue
Links:
🔗 12 Factor apps: 12factor.net/
🔗 Basics around runtimeConfig: • Is Nuxt 3's runtimeCon...
🔗 Code: github.com/manniL/nuxt3-runti...
🔗 Docs PR for the mistake: github.com/nuxt/nuxt/pull/24612
Don't forget to hit that "Subscribe" button, ring the notification bell and give a thumbs up!
🌐 Connect further:
Website: www.lichter.io
Twitter/X: / thealexlichter
Twitch: / thealexlichter
Chapters:
00:00 Intro
00:52 Diving into the demo app
02:06 The actual mistake
03:20 No changes reflected - but why?
04:25 Solution and other non-working scenarios
05:40 Beyond creating content - Updating the docs!
06:23 Summary - Наука та технологія
Did you made that mistake so far? 👀
The env vars make me crazy.
Everything works fine on dev, but when deploy to prod, here where troubles come.
I Use kubernetes for deploy, and every time I have some problems with env variables, especially with modules.
My kubernetes has all env variables, but app cannot check them properly
Great video! Thank you for giving a great insight about env variable in nuxt🙏
You are welcome Erfran! 😊
Your vids are godsend, thank you man
You are more than welcome! Glad they help you ✌
thanks:) will keep in mind in my future projects
Perfect 🙌
Life saver! thank you.
Thank you!
My pleasure 🙏
OMG THANK YOU ❤
No problem ✅
Time for me to update some of my answers on SO. :3
Props for doing that 🙌💚
Thanks for clarification. I have one question though: How do you handle when to need runtime environment variable inside the nuxt.config.ts? Because useRuntimeConfig is not defined at this moment.
You usually don’t. Modules should provide a runtimeConfig support so you can change that.
Using env variables works fine in the nuxt config when only setting things on build though, so not when starting the app. But I’d suggest to go for runtimeConfig
What is the intellisense for Nuxt that shows you it can be overridden?
Actually they are just Nuxts TS types (after the dev server ran with the changes)!
thank you
You're welcome 😊
good thank you
You are welcome!
Idk, to me it seems perfectly valid to have these values baked in / static after building, while still allowing the option to override them if needed with a special env var.
It is valid to have them baked in, no doubts. But then you can either use simple static strings in the config *or* the same env variable for overriding anyway ☺️
I used it for api base url and some fixed global variables 😊
Perfect 👍🏻
This was an absolute garbage of a decision by the Vue/Nuxt team. This showed me how detached they are from their user base, ignoring everyone on Nuxt v2 and making it extra hard to migrate
Why does it make migration difficult?