Vite environment variables do not take effect

Vite uses environment variables, and import.meta.env.VITE_XXX in the project shows undefined

Anyone who has gotten to this point should be aware of the configuration of environment variables, so I won’t elaborate further. It should go without saying that only variables starting with VITE are recognized by default.
After VITE creates the project, there is an .env.development file. This file is used by default when the development environment is running. However, the value undefined cannot be read in the project, and only the default items can be read.

Solution : Delete the file and re-damage it (if you know the specific reason why it needs to be re-damaged, please let me know, thank you. I will study it again when I have time. I have been stuck on this pit for a long time)

Guess you like

Origin blog.csdn.net/drunk2/article/details/130835713