When using api google translation I encountered the same problem. I was unable to reference the entire JSON file, so I created two env variables in Heroku and referenced them in the credential object. You cannot leave them alone. Private key replacement is an important detail. You must insert this full key, as on Heroku.
const Translate = require('@google-cloud/translate');
const projectId = 'your project id here';
const translate = new Translate({
projectId: projectId,
credentials: {
private_key: process.env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'),
client_email: process.env.GOOGLE_CLIENT_EMAIL
}
});
source
share