title: Firebase deploy functions Error with Koa in TypeScript
body: <p>I've been trying to deploy firebase functions using Koa in TypeScript.
  But I cannot figure out what the problem is. Could anybody help me?</p>
  <p>File structure looks like this:</p>
  <pre><code>├── functions/
  │    ├── lib/
  │    ├── node_modules/
  │    └── src/
  │         ├── index.ts
  │         ├── .eslintrc.js
  │         ├── package.json
  │         ├── package-lock.json
  │         ├── tsconfig.dev.json
  │         └── tsconfig.json
  │
  ├── .firebaserc
  └── firebase.json
  </code></pre>
  <p>If I just deploy sameple <code>helloWorld()</code> in <code>index.ts</code> file, then I could deploy function. But for some reason I've tried to deploy Koa server to firebase functions, it keeps failing saying:</p>
  <pre><code>Functions deploy had errors with the following functions:
      app(asia-northeast3)
  
  To try redeploying those functions, run:
      firebase deploy --only &quot;functions:app&quot;
  
  To continue deploying other features (such as database), run:
      firebase deploy --except functions
  
  Error: Functions did not deploy properly.
  npm ERR! code 1
  npm ERR! path /workspace/myproj/functions
  npm ERR! command failed
  npm ERR! command sh -c firebase deploy --only functions
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /Users/me/.npm/_logs/2021-07-27T15_44_39_569Z-debug.log
  </code></pre>
  <p><code>$ firebase serve --only functions</code> works fine. But <code>$ firebase deploy --only functions</code> doesn't work. And here's my code.</p>
  <pre class="lang-js prettyprint-override"><code>// functions/src/index.ts
  
  import * as functions from &quot;firebase-functions&quot;
  import Router from &quot;koa-router&quot;
  import Koa from &quot;koa&quot;
  
  export const app = new Koa()
  const router = new Router()
  
  router.get(&quot;/&quot;, (ctx) =&gt; {
      ctx.body = &quot;Okay&quot;
  })
  
  app.use(router.routes()).use(router.allowedMethods())
  
  exports.app = functions
      .region(&quot;asia-northeast3&quot;)
      .https.onRequest(app.callback())
  </code></pre>
  <pre class="lang-json prettyprint-override"><code>// functions/package.json
  
  {
    &quot;name&quot;: &quot;functions&quot;,
    &quot;scripts&quot;: {
      &quot;lint&quot;: &quot;eslint --ext .js,.ts .&quot;,
      &quot;build&quot;: &quot;tsc&quot;,
      &quot;serve&quot;: &quot;npm run build &amp;&amp; firebase emulators:start --only functions&quot;,
      &quot;shell&quot;: &quot;npm run build &amp;&amp; firebase functions:shell&quot;,
      &quot;start&quot;: &quot;npm run shell&quot;,
      &quot;deploy&quot;: &quot;firebase deploy --only functions&quot;,
      &quot;logs&quot;: &quot;firebase functions:log&quot;
    },
    &quot;engines&quot;: {
      &quot;node&quot;: &quot;14&quot;
    },
    &quot;main&quot;: &quot;lib/index.js&quot;,
    &quot;dependencies&quot;: {
      &quot;firebase-admin&quot;: &quot;^9.8.0&quot;,
      &quot;firebase-functions&quot;: &quot;^3.14.1&quot;,
      &quot;koa-router&quot;: &quot;^10.0.0&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@types/koa&quot;: &quot;^2.13.4&quot;,
      &quot;@types/koa-router&quot;: &quot;^7.4.4&quot;,
      &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^3.9.1&quot;,
      &quot;@typescript-eslint/parser&quot;: &quot;^3.8.0&quot;,
      &quot;eslint&quot;: &quot;^7.6.0&quot;,
      &quot;eslint-config-google&quot;: &quot;^0.14.0&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.22.0&quot;,
      &quot;firebase-functions-test&quot;: &quot;^0.2.0&quot;,
      &quot;koa&quot;: &quot;^2.13.1&quot;,
      &quot;prettier&quot;: &quot;^2.3.2&quot;,
      &quot;typescript&quot;: &quot;^3.8.0&quot;
    },
    &quot;private&quot;: true
  }
  </code></pre>
  <pre class="lang-json prettyprint-override"><code>// functions/tsconfig.json
  
  {
    &quot;compilerOptions&quot;: {
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;noImplicitReturns&quot;: true,
      &quot;noUnusedLocals&quot;: true,
      &quot;outDir&quot;: &quot;lib&quot;,
      &quot;sourceMap&quot;: true,
      &quot;strict&quot;: true,
      &quot;target&quot;: &quot;es2017&quot;,
      &quot;esModuleInterop&quot;: true
    },
    &quot;compileOnSave&quot;: true,
    &quot;include&quot;: [
      &quot;src&quot;
    ]
  }
  </code></pre>
  <pre class="lang-json prettyprint-override"><code>// firebase.json
  
  {
    &quot;functions&quot;: {
      &quot;predeploy&quot;: [
        &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run lint&quot;,
        &quot;npm --prefix \&quot;$RESOURCE_DIR\&quot; run build&quot;
      ]
    }
  }
  </code></pre>
  <p>Thank you in advance guys!!!</p>