title: ReferenceError: resolve is not defined
body: <p>I have a function to call the google speech API. Looks all is good but I cannot find why it is giving me the error. I am a beginner with node and promises so not sure why this error appears.</p>
  <blockquote>
  <p>ReferenceError: resolve is not defined at index.js:57</p>
  </blockquote>
  <p>The problem is in this part of the code:</p>
  <pre><code>  return speech
      .longRunningRecognize(responses)
      .then(function(results) {
        var operation = responses[0];
        console.log(&quot;Operation: &quot;, operation);
        return operation.promise();
      })
      .then(function(responses) {
        resolve(responses[0]);
        console.log(&quot;Result: &quot;, JSON.stringify(responses[0]));
      })
  </code></pre>
  <p>Where the promise</p>
  <blockquote>
  <p>operation.promise() (line 57)</p>
  </blockquote>
  <p>cannot be resolved. It wants to resolve
  the promise, but it looks like it cannot find the resolve function.</p>
  <p>The Google API works like this:</p>
  <ul>
  <li>First, you do an api call to upload your data and start the process.</li>
  <li>This gives you back an operation name.</li>
  <li>This name should be used subsequently to get the result when the result is ready (only takes max 30 sec)</li>
  </ul>
  <p>I have the feeling it's all working, the call is made, the response comes back. The code waits and then it wants to resolve but it cannot...</p>
  <p>My code is like this (its a cloud function)</p>
  <pre><code>  exports.transcribeAudio = functions.storage.object().onChange(event =&gt; {
    const object = event.data;
    const filePath = object.name;
    const fileName = filePath.split(&quot;/&quot;).pop();
    const fileBucket = object.bucket;
    const bucket = gcs.bucket(fileBucket);
    const tempFilePath = path.join(os.tmpdir(), fileName);
  
    // Exit if this is triggered on a file that is not an image.
    // Get the file name.
    //const fileName = path.basename(filePath);
    console.log(filePath + &quot; name: &quot; + fileName);
    // Exit if the image is already a thumbnail.
    if (!filePath.startsWith(&quot;ucl-flac-audio&quot;)) {
      console.log(&quot;Only flac-audio need to be converted&quot;);
      return true;
    }
    // Exit if this is a move or deletion event.
    if (object.resourceState === &quot;not_exists&quot;) {
      console.log(&quot;This is a deletion event.&quot;);
      return true;
    }
  
    return Promise.resolve()
      .then(() =&gt; {
        const audioFilename = &quot;gs://&quot; + fileBucket + &quot;/&quot; + filePath;
        console.log(audioFilename);
        const request = {
          config: {
            encoding: &quot;FLAC&quot;,
            languageCode: &quot;fr-FR&quot;
          },
          audio: {
            uri: audioFilename
          }
        };
  
        return speech
          .longRunningRecognize(request)
          .then(function(responses) {
            var operation = responses[0];
            console.log(&quot;Operation: &quot;, operation);
            return operation.promise();
          })
          .then(function(responses) {
            resolve(responses[0]);
            console.log(&quot;Result: &quot;, JSON.stringify(responses[0]));
          })
          .catch(function(err) {
            console.error(&quot;Failed to get transcript.&quot;, err);
            //    reject(err);
          });
      })
      .catch(err =&gt; {
        return Promise.reject(err);
      });
  });
  </code></pre>