Google Maps JavaScript API RefererNotAllowedMapError and Github .env File

https://miro.medium.com/max/1400/1*_cPilbvs66iLoCN-IAro8Q.png

Clone Sample won’t work at npm start

sample project: Place Searches | Maps JavaScript API | Google Developers

1
2
3
4
git clone -b sample-place-search https://github.com/googlemaps/js-samples.git  
cd js-samples  
npm i  
npm start

https://miro.medium.com/max/1400/1*NNPJUJRF_glAG_r_R3N4YA.png

A message like this kept showing up. If you clicked in docs, it only gave you useless instructions that won’t work even if you tried million times.

https://miro.medium.com/max/1400/1*SpICuYXzzE5t3Vnvoph11w.png

How to solve it?

First, go to See the Maps JavaScript API and Get an API Key.

https://miro.medium.com/max/1400/1*SZS3VnnMQF802kHz3uD7LQ.png

Make sure you have Maps API Key and empty the others to troubleshoot.

Somehow npm run build / vite build don’t use .env to update your API key in index.html.

https://miro.medium.com/max/738/1*_NhGQlapt4TnyaKbwrKxNg.png

https://miro.medium.com/max/1400/1*et_LLwmRS6y29lXd-D0z8A.png

And, don’t forget to protect you key like mine here:

https://miro.medium.com/max/1400/1*toyjUqftICji3Um60JfXHA.png

https://miro.medium.com/max/1400/1*YLFrvUP4SHeufcw19FbRtw.png

Resources:

Google Maps JavaScript API RefererNotAllowedMapError — Stack Overflow

Google Maps Javascript API Error “RefererNotAllowedMapError” — GravityKit Support, Knowledge Base, How-To & Docs

How to use GitHub Actions secrets to hide your tokens and passwords example

What if I want to use API key in build/Productionby creating .env file.

My example: (add a workflow to manually overwrite or create one .env)

https://miro.medium.com/max/1400/1*ow5G9boSjgG70gnMMNVqKA.png

Set up your API key by Github Actions Secrets

https://miro.medium.com/max/1400/1*TCjCLN3B1mhBzBXqByLNHw.png

Resources:

Create .env file · Actions · GitHub Marketplace

environment variables — How do I use an env file with GitHub Actions? — Stack Overflow

How to use GitHub Actions secrets to hide your tokens and passwords example (theserverside.com)

Contact me: Hung, Chien-Hsiang (chienhsiang-hung.github.io)