title: firebase functions can't deploy. Unexpected token function
body: <p>Ok so I just found out that firebase functions supports node 8 because I'm getting an error that says "Unexpected token functions" where the first "async" is. </p>
  
  <p>Google says put this in the package json. </p>
  
  <p>"engines": {"node": "8"}</p>
  
  <p>but I put it there and it does nothing. Do any of you know what's wrong?</p>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "functions",
    "description": "Cloud Functions for Firebase",
    "scripts": {
      "lint": "eslint .",
      "serve": "firebase serve --only functions",
      "shell": "firebase functions:shell",
      "start": "npm run shell",
      "deploy": "firebase deploy --only functions",
      "logs": "firebase functions:log"
    },
    "dependencies": {
      "firebase-admin": "~6.1.0",
      "firebase-functions": "^2.0.3"
    },
    "engines": {"node": "8"},
    "devDependencies": {
      "eslint": "^5.7.0",
      "eslint-plugin-promise": "^4.0.1"
    },
    "private": true
  }
  </code></pre>
  
  <p>index.js</p>
  
  <pre><code>const functions = require('firebase-functions');
  const request = require('request');
  const admin = require('firebase-admin');
  const serviceAccount = require("./service-key.json");
  
  admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "*"
  });
  
  exports.helloWorld = functions.https.onRequest((request, response) =&gt; {
   response.send("Hello from Firebase!");
  });
  
  exports.getEvents = functions.https.onRequest(() =&gt; {
      request.get('*', (error, response, body) =&gt; {
          console.log('error:', error);
          console.log('statusCode:', response &amp;&amp; response.statusCode);
          console.log('body:', body);
  
          var data = { "events": body };
  
          function isCollection(data, path, depth) {
              if (
                typeof data != 'object' ||
                data == null ||
                data.length === 0 ||
                isEmpty(data)
              ) {
                return false;
              }
  
              for (const key in data) {
                if (typeof data[key] != 'object' || data[key] == null) {
                  // If there is at least one non-object item then it data then it cannot be collection.
                  return false;
                }
              }
  
              return true;
            }
  
            // Checks if object is empty.
            function isEmpty(obj) {
              for(const key in obj) {
                if(obj.hasOwnProperty(key)) {
                  return false;
                }
              }
              return true;
            }
  
            async function upload(data, path) {
              return await admin.firestore()
                // .collection('/lineup2018')
                .doc(path.join('/'))
                .set(data)
                .then(() =&gt; console.log(`Document ${path.join('/')} uploaded.`))
                .catch(() =&gt; console.error(`Could not write document ${path.join('/')}.`));
            }
  
            /**
             *
             */
            async function resolve(data, path = []) {
              if (path.length &gt; 0 &amp;&amp; path.length % 2 == 0) {
                // Document's length of path is always even, however, one of keys can actually be a collection.
  
                // Copy an object.
                const documentData = Object.assign({}, data);
  
                for (const key in data) {
                  // Resolve each collection and remove it from document data.
                  if (isCollection(data[key], [...path, key])) {
                    // Remove a collection from the document data.
                    delete documentData[key];
                    // Resolve a colleciton.
                    resolve(data[key], [...path, key]);
                  }
                }
  
                // If document is empty then it means it only consisted of collections.
                if (!isEmpty(documentData)) {
                  // Upload a document free of collections.
                  await upload(documentData, path);
                }
              } else {
                // Collection's length of is always odd.
                for (const key in data) {
                  // Resolve each collection.
                  await resolve(data[key], [...path, key]);
                }
              }
            }
  
            resolve(data);
      });
  });
  </code></pre>
  
  <p>EDIT: turns out the function is running on node.js but I still get the error because of async and await. Maybe it's the eslint that is doing something weird.</p>