none
Unable to run TypeScript Function locally RRS feed

  • Question

  • Hello. I am trying to locally run my TypeScript Azure Function app. I created it in Visual Studio Code with the help of the Azure Functions Extension (As documented on the Function Apps documentation page). Instead of an HTTP Trigger, I am using the Event Hub Trigger, as that is what I am going to need to use for my use case. I walked through the setup prompts and used the default values (I also already have an Event Hub Instance running, which I was able to connect too using the prompts).

    I Published my function app using VS Code and was able to observe that it was executing correctly in Azure. 

    However, when I try and execute my function locally, it fails to run. I have tried running it locally using:

    1. npm install && npm start
    2. func start

    Both methods fail. 

    Shell output:

    [9/17/19 4:02:05 PM] Found the following functions:
    [9/17/19 4:02:05 PM] Host.Functions.EventHubTrigger
    [9/17/19 4:02:05 PM] 
    [9/17/19 4:02:05 PM] Host initialized (673ms)
    [9/17/19 4:02:05 PM] The listener for function 'Functions.EventHubTrigger' was unable to start.
    [9/17/19 4:02:05 PM] The listener for function 'Functions.EventHubTrigger' was unable to start. Microsoft.Azure.EventHubs.Processor: Encountered error while fetching the list of EventHub PartitionIds. Microsoft.Azure.EventHubs: Could not load file or assembly 'Microsoft.Azure.Amqp, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
    [9/17/19 4:02:05 PM] . System.Private.CoreLib: Could not load the specified file.
    [9/17/19 4:02:05 PM] Host started (834ms)
    [9/17/19 4:02:05 PM] Job host started
    Hosting environment: Production
    Content root path: /Path/To/Function/App/VsCodeTypeScriptTest
    Now listening on: http://0.0.0.0:7071
    Application started. Press Ctrl+C to shut down.
    [9/17/19 4:02:07 PM] Retrying to start listener for function 'Functions.EventHubTrigger' (Attempt 1)
    [9/17/19 4:02:08 PM] The listener for function 'Functions.EventHubTrigger' was unable to start.
    [9/17/19 4:02:08 PM] The listener for function 'Functions.EventHubTrigger' was unable to start. Microsoft.Azure.EventHubs.Processor: Encountered error while fetching the list of EventHub PartitionIds. Microsoft.Azure.EventHubs: Could not load file or assembly 'Microsoft.Azure.Amqp, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
    [9/17/19 4:02:08 PM] . System.Private.CoreLib: Could not load the specified file.
    [9/17/19 4:02:11 PM] Host lock lease acquired by instance ID '000000000000000000000000264FE689'.

    Code Files

    index.ts

    import { AzureFunction, Context } from "@azure/functions"
    
    const eventHubTrigger: AzureFunction = async function (context: Context, eventHubMessages: any[]): Promise<void> {
        context.log(`Eventhub trigger function called for message array ${eventHubMessages}`);
        
        eventHubMessages.forEach((message, index) => {
            context.log(`Processed message ${message}`);
        });
    };
    
    export default eventHubTrigger;
    


    function.json

    {
      "bindings": [
        {
          "type": "eventHubTrigger",
          "name": "eventHubMessages",
          "direction": "in",
          "eventHubName": "eh-test-raw-1",
          "connection": "eh-test-raw_RootManageSharedAccessKey_EVENTHUB",
          "cardinality": "many",
          "consumerGroup": "$Default"
        }
      ],
      "scriptFile": "../dist/EventHubTrigger/index.js"
    }
    


    host.json

    {
      "version": "2.0",
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
      }
    }
    

    local.settings.json

    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "DefaultEndpointsProtocol=<Hidden, pulled from app settings in the published function app>",
        "FUNCTIONS_WORKER_RUNTIME": "node",
        "eh-test-raw_RootManageSharedAccessKey_EVENTHUB": "Endpoint=sb://eh-test-raw.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<hidden>;EntityPath=eh-test-raw-1"
      }
    }
    

    package.json

    {
      "name": "VsCodeTypeScriptTest",
      "version": "1.0.0",
      "description": "",
      "scripts": {
        "build": "tsc",
        "watch": "tsc -w",
        "prestart": "npm run build && func extensions install",
        "start:host": "func start",
        "start": "npm run start:host & npm run watch",
        "build:production": "npm run prestart && npm prune --production",
        "test": "echo \"No tests yet...\""
      },
      "dependencies": {},
      "devDependencies": {
        "@azure/functions": "^1.0.2-beta2",
        "typescript": "^3.3.3"
      }
    }
    

    tsconfig.json

    {
      "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "outDir": "dist",
        "rootDir": ".",
        "sourceMap": true,
        "strict": false
      }
    }
    


    Tuesday, September 17, 2019 5:28 PM

All replies

  • Hello TeraInferno,

    I tried this at my side and it worked perfectly fine. I can reproduce the issue when I explicitly deleted the file Microsoft.Azure.Amqp.dll from the location "C:\Users\<UserName>\AppData\Local\Temp\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\1.0.0\bin"

    Once I removed the file, I am getting the same error as yours.

    To resolve the issue , delete the ExtensionBundles folder ("C:\Users\<UserName>\AppData\Local\Temp\Functions\) and rerun the function, it will install the extension bundles back.

    Wednesday, September 18, 2019 6:34 AM
    Moderator