title: Google Cloud Storage call fails with "error:0909006C:PEM routines:get_name:no start line" when run in Blitz.js api handler
body: <p>When I try to use <a href="https://www.npmjs.com/package/@google-cloud/storage" rel="nofollow noreferrer">@google-cloud/storage</a> inside of a <a href="https://blitzjs.com/docs/api-routes" rel="nofollow noreferrer">Blitz.js /api handler</a>, it generates this error:</p>
  <pre><code>error:0909006C:PEM routines:get_name:no start line
      at Sign.sign (internal/crypto/sig.js:110:29)
      at NodeCrypto.sign (C:\Users\markj\workspace\myapp\node_modules\google-auth-library\build\src\crypto\node\crypto.js:35:23)
      at GoogleAuth.sign (C:\Users\markj\workspace\myapp\node_modules\google-auth-library\build\src\auth\googleauth.js:561:39)
      at runMicrotasks (&lt;anonymous&gt;)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at async sign (C:\Users\markj\workspace\myapp\node_modules\@google-cloud\storage\build\src\signer.js:174:35) {
    name: 'SigningError'
  </code></pre>
  <p>However when I run it locally with <code>node test_api.js</code>, it works fine...</p>
  <p>Here is my code:</p>
  <pre class="lang-js prettyprint-override"><code>// test_api.js
  
  const {Storage} = require('@google-cloud/storage');
  
  const client_id = process.env.GCP_STORAGE_ADMIN_CLIENT_ID
  const projectId = process.env.GCP_PROJECT_ID
  const client_email = process.env.GCP_STORAGE_ADMIN_CLIENT_EMAIL
  const private_key = process.env.GCP_STORAGE_ADMIN_PRIVATE_KEY
  
  const storage = new Storage({
      projectId,
      credentials: {
          client_id,
          client_email,
          private_key,
      }
  });
  
  async function listBuckets() {
      console.log('PRIVATE KEY: ', private_key) // the error seems to indicate there is an issue here
      // Output: &quot;-----BEGIN PRIVATE KEY-----\n[the private key]\n-----END PRIVATE KEY-----\n&quot;
      const [buckets] = await storage.getBuckets();
      console.log('Buckets:');
      buckets.forEach(bucket =&gt; {
        console.log(bucket.name);
      });
  }
  
  module.exports = {
      listBuckets // this function errors when called within Next.js /api handler
  }
  
  // When I uncomment this and run the file directly with node, it works
  // listBuckets()
  </code></pre>
  <p>The error seems to indicate there is something wrong with the start/prefix of my private key, but I copied it exactly from the Google Service Account JSON file. It looks like this:</p>
  <p><code>-----BEGIN PRIVATE KEY-----\n[the private key]\n-----END PRIVATE KEY-----\n</code></p>