Under Ubuntu environment, NodeJS Google Vision complains:
Error: Unable to detect a Project Id in the current environment.
Even though I already put json credential through
$ export GOOGLE_APPLICATION_CREDENTIALS=/var/credential_google.json"
Please help.
If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id. You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running. It will load the project environment.
How to Find Google Project ID 1 Go to the API Console. 2 From the projects list, select Manage all projects. The names and IDs for all the projects you're a member of are displayed. See More....
You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running. It will load the project environment. This also allows you to deploy easier with: App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.
There are two ways to identify your project: the project name and project ID. You create the project name when you create the project. The project ID is a unique identifier for a project and is used only within the console. When you first create a project, you can accept the default generated project ID or create your own.
It's not recommended to use a .json config file locally. I've seen these leak on production servers causing whole platforms to be deleted + the introduce environmental switching and security issues.
Setup Google Cloud CLI.
Now the server will 'look' at the local environment and use that.
If you get the error "Unable to detect a Project Id in the current environment.", it means the auth library cannot find the project default id.
You need to have a base project in Google Cloud set, regardless of environmental variables and project you're running.
Run
gcloud config set project [some-project-id]
Now if you run (node example)
"dev": "NODE_ENV=dev GCP_PROJECT=some-project-id nodemon index.ts",
It will load the project environment. This also allows you to deploy easier with:
"deploy:dev": "y | gcloud app deploy --project some-dev-project app.yaml",
"deploy:prod": "y | gcloud app deploy --project some-prod-project app.yaml"
App engine has security setup automatically with standard environments. With flex you can use one of the manage images Google Provides.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With