The build shows ${L}... instead of the actual API key, meaning Vite is not substituting the environment variable during build.
Vite uses .env.production for production builds. If it doesn't exist, variables may not be substituted.
cd /root/stairs-new
bash fix-vite-env-substitution.shThis will:
- โ
Create
.env.productionfile with the browser key - โ
Update
.envfile - โ Clean build directory
- โ Rebuild with explicit environment variable
- โ Verify key in built files
cd /root/stairs-new/frontend
# 1. Get the browser key from .env
BROWSER_KEY=$(grep "^VITE_GOOGLE_MAPS_API_KEY=" .env | cut -d'=' -f2 | tr -d '"' | tr -d "'" | tr -d ' ')
# 2. Create .env.production file
cat > .env.production << EOF
VITE_GOOGLE_MAPS_API_KEY=$BROWSER_KEY
EOF
# 3. Clean and rebuild
rm -rf dist node_modules/.vite
VITE_GOOGLE_MAPS_API_KEY="$BROWSER_KEY" npm run buildVite reads environment variables from:
.env- for all modes.env.production- for production builds (overrides .env).env.local- local overrides (gitignored)
If .env.production doesn't exist, Vite might not properly substitute variables in production builds.
After rebuilding:
# Check built files
grep -r "maps.googleapis.com" dist/ | grep "key=" | head -1
# Should show the actual key, NOT ${VITE_GOOGLE_MAPS_API_KEY}Even after fixing the build, make sure:
- Browser key exists and is different from server key
- HTTP referer restrictions are set (NOT IP)
- Checkboxes are CHECKED for referers:
https://portal.stairs.org.in/*https://*.portal.stairs.org.in/*https://www.portal.stairs.org.in/*
Run fix-vite-env-substitution.sh to fix the build issue!