title: Azure Function: Can't figure out which ctor to call
body: <p>I am building an API that is published to Azure Functions. I currently have two working functions, and I've written a third that I can't get to work after deploying. </p>
  
  <p>It works when running locally using <code>func start</code> and pointing <code>scriptFile</code> in <code>function.json</code> to the same transpiled file as I'm deploying to Azure.</p>
  
  <p>This is what the contents look like when I download them from the function runtime:</p>
  
  <pre><code>├── host.json
  ├── node_modules/
  ├── FunctionA
  │   ├── function.json
  │   ├── index.js
  │   └── index.js.map
  ├── proxies.json
  ├── FunctionB
  │   ├── function.json
  │   ├── index.js
  │   └── index.js.map
  └── FunctionC
      ├── function.json
      ├── index.js
      └── index.js.map
  </code></pre>
  
  <p><code>FunctionA</code> and <code>FunctionB</code> work. The main difference in <code>FunctionC</code> is that this function has a dependency to a <code>node_modules</code> dependency, <code>@azure/cosmos</code>.</p>
  
  <p>I build all my functions identically, <code>npx parcel build index.ts --target node</code>. According to the parcel docs:</p>
  
  <blockquote>
    <p>Target node and electron will not bundle package.json's dependencies</p>
  </blockquote>
  
  <p>Exactly what I want, since the <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#deploying-with-dependencies" rel="nofollow noreferrer">developer guidelines</a> state this is how you handle dependencies in an Azure Function using Javascript:</p>
  
  <blockquote>
    <ol>
    <li>Install all requisite packages locally by running npm install.</li>
    <li>Deploy your code, and ensure that the node_modules folder is included in the deployment.</li>
    </ol>
  </blockquote>
  
  <p>The <code>node_modules</code> folder I provide is the one resulting from running <code>npm install --production</code> since I don't want the other dependencies.</p>
  
  <p>But when I go to check this function in Azure Portal, I see the following error when entering the code view:</p>
  
  <blockquote>
    <p>Function (FunctionC) Error: Can't figure out which ctor to call. </p>
  </blockquote>
  
  <p>The function itself looks like this in TypeScript:</p>
  
  <pre class="lang-js prettyprint-override"><code>// Omitted imports
  const functionC: AzureFunction = async function (context: Context, events: CustomEvent[]): Promise&lt;void&gt; {
      try {
          // Extract data about Cosmos database and container
          const cosmosOutBinding = await FunctionUtil.getBindingByName(context.executionContext.functionDirectory, "documentOut")
  
          const cosmosConnection: CosmosDB = new CosmosDB(process.env.COSMOSDB_CONNECTION_STRING, cosmosOutBinding.databaseName)
          const updateContext: UpdateContext = new UpdateContext(context, cosmosConnection, cosmosOutBinding.collectionName)
  
          await updateContext.handleEvents(events)
      } catch (error) {
          context.log.error('Failed', error)
      }
  }
  
  export default functionC
  </code></pre>
  
  <p>The <code>UpdateContext</code> is a imported class and contains the main logic of the function. I've structured it this way to have it testable.</p>
  
  <p>And finally, the bindings for this function:</p>
  
  <pre><code>{
    "bindings": [
      {
        "type": "eventHubTrigger",
        "name": "events",
        "direction": "in",
        "eventHubName": "some-hub",
        "connection": "EVENT_HUB_CONNECTION_STRING",
        "cardinality": "many",
        "consumerGroup": "events"
      },
      {
        "name": "documentOut",
        "type": "cosmosDB",
        "databaseName": "dev",
        "collectionName": "asdf",
        "createIfNotExists": false,
        "connectionStringSetting": "COSMOSDB_CONNECTION_STRING",
        "direction": "out"
      }
    ]
  }
  </code></pre>
  
  <p>I can't wrap my head around what is wrong here. Any pointers in the right direction would be very appreciated.</p>