title: TypeError: key must be a string, a buffer or an object at typeError with GCP file exists
body: <p>I'm trying to simply test for an existence of a file on our Google Cloud Platform (GCP) storage. I'm using GCP buckets on express js servers. Below is essentially a very simple exampled copied off of <a href="https://googleapis.dev/nodejs/storage/latest/File.html#exists" rel="nofollow noreferrer">https://googleapis.dev/nodejs/storage/latest/File.html#exists</a></p>
  <p>EDIT: This is how I authenticate the GCP key:</p>
  <pre><code>const { Storage } = require('@google-cloud/storage');
  
  const storage = new Storage({
      projectId: 'my-cloud',
      keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
  });
  const bucketName = 'my-ci';
  </code></pre>
  <p>(With small changes, I realise you are supposed to return <code>data[0]</code>)</p>
  <pre class="lang-js prettyprint-override"><code>const bucket = storage.bucket(bucketName);
  const file = bucket.file(path);
  const exists = await file.exists().then(data =&gt; {
      return data
  })
  </code></pre>
  <p>But when I try run this, I get the error:</p>
  <pre><code>[nodemon] starting `node --inspect server/server.js`
  Debugger listening on ws://127.0.0.1:9229/9a677766-4a93-4499-b57c-55f5f05096d7
  For help, see: https://nodejs.org/en/docs/inspector
  Server listening on port 4000!
  /opt/node_modules/jwa/index.js:115
  return new TypeError(errMsg);
  ^
  
  TypeError: key must be a string, a buffer or an object
  at typeError (/opt/node_modules/jwa/index.js:115:10)
  at checkIsPrivateKey (/opt/node_modules/jwa/index.js:61:9)
  at Object.sign (/opt/node_modules/jwa/index.js:147:5)
  at Object.jwsSign [as sign] (/opt/node_modules/jws/lib/sign-stream.js:32:24)
  at JWTAccess.getRequestHeaders (/opt/node_modules/google-auth-library/build/src/auth/jwtaccess.js:87:31)
  at JWT.getRequestMetadataAsync (/opt/node_modules/google-auth-library/build/src/auth/jwtclient.js:76:51)
  at JWT.getRequestHeaders (/opt/node_modules/google-auth-library/build/src/auth/oauth2client.js:238:37)
  at GoogleAuth.authorizeRequest (/opt/node_modules/google-auth-library/build/src/auth/googleauth.js:593:38)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  </code></pre>
  <p>Since the error message did not give a useful traceback, I did some digging on my own. Through putting <code>console.log</code> statements everywhere, I narrowed it down to the line</p>
  <pre class="lang-js prettyprint-override"><code>const exists = await file.exists().then(data =&gt; {
      return data
  })
  
  </code></pre>
  <p>and tried various approaches from removing the <code>.then(...)</code> clause, to removing the <code>await</code> (which, does work until the promise is resolved). None of these seemed to have worked.</p>
  <p>What may be potential causes of this?</p>