I could not setup an environment variable using Vite and Netlify, I used "import.meta.env.VITE_KEY" in my local file and .env (it works great, locally), but at Netlify it was showing undefined and failing to fetch the leaflet map.
Mike Schepers
@mike1233All comments
- @cassio9Submitted almost 2 years ago@mike1233Posted almost 2 years ago
Hello,
To answer your queston about env variables. you need to set the variable in the command line before you execute the vite build command.
vite docs:
In addition, environment variables that already exist when Vite is executed have the highest priority and will not be overwritten by .env files. For example, when running VITE_SOME_KEY=123 vite build.
in my case i had to do the following with github actions
- name: Install 🔧 run: npm ci - name: Build 🏗️ run: npm run build env: VITE_GEOLOCATION_API_KEY: ${{secrets.apikey}}
Now i dont know exactly how your deployprocess works with netlify but i hope this points you into the right direction!
1