0

project structure:

<root-directory>
├── README.md
├── dist
├── bin
├── dependencies
├── host.json
├── local.settings.json
├── node_modules
├── package-lock.json
├── package.json
├── sealworker
│   ├── constants
│   ├── errors
│   ├── function.json
│   ├── index.ts
│   ├── interfaces
│   ├── sample.dat
│   ├── services
│   ├── utils
│   └── worker.ts
└── tsconfig.json

function.json:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "entryPoint": "sealWorkerFunction",
  "scriptFile": "../dist/sealworker/index.js"
}

/sealworker/index.ts:

import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import workerExec from "./worker";

const sealWorkerFunction: AzureFunction = async function (
  context: Context,
  req: HttpRequest
): Promise<void> {
  const responseMessage = "example";
  const result = await workerExec(req, context);

  context.res = {
    // status: 200, /* Defaults to 200 */
    body: responseMessage,
  };
};

export default { sealWorkerFunction };

/sealworker/worker.ts:

import "dotenv/config";
import "reflect-metadata";
import { HttpRequest, Context } from "@azure/functions";

const workerExec = async (req: HttpRequest, context: Context) => {
  context.log("start....");
  const message = req.body;
  context.log("message: ", message);
  return { result: "dummy" };
};

export default workerExec;

Error message:

Result: Failure Exception: Worker was unable to load function sealworker: 'Unable to determine function entry point: sealWorkerFunction. If multiple functions are exported, you must indicate the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.' Stack: Error: Worker was unable to load function sealworker: 'Unable to determine function entry point: sealWorkerFunction. If multiple functions are exported, you must indicate the entry point, either by naming it 'run' or 'index', or by naming it explicitly via the 'entryPoint' metadata property.' at /azure-functions-host/workers/node/dist/src/worker-bundle.js:2:14706 at t.LegacyFunctionLoader. (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:14945) at Generator.next () at o (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:13387) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

oh and this is the dist/sealworker/index.js after build:

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const worker_1 = __importDefault(require("./worker"));

const sealWorkerFunction = function (context, req) {
    return __awaiter(this, void 0, void 0, function* () {
        const name = req.query.name || (req.body && req.body.name);
        const responseMessage = name
            ? "Hello, " + name + ". This HTTP triggered function executed successfully."
            : "This HTTP triggered function executed successfully. Pass a name in the query string or in the req body for a personalized response.";
        context.log(`Http function processed req for url "${req.url}"`);
        const message = req.body;
        context.log("type of message: ", typeof message);
        context.log("message: ", message);
        const result = yield (0, worker_1.default)(req, context);
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: responseMessage,
        };
    });
};
exports.default = { sealWorkerFunction };
//# sourceMappingURL=index.js.map

I have followed the documentations on how to correctly configure the entry point for Azure linux typescript nodejs function. But I must have missed something.

Any suggestions?

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
Kid_Learning_C
  • 2,605
  • 4
  • 39
  • 71
  • Did you mean to write `export default sealWorkerFunction;`? What you've done is provide a default export which is an object containing a single method. I'm not sure if this was intentional or not but it does mean that your entry point is wrong. How would the runtime know to dereference the property pointing to the method on the default export given how you specified the entry point? – Aluan Haddad Aug 09 '23 at 00:12

1 Answers1

1

Initially I was also getting the error but after making export {sealWorkerFunction} modification in my index.ts file, it worked for me.

Code:

index.ts

import { AzureFunction, Context, HttpRequest } from  "@azure/functions";
import  workerExec  from  "./worker";
const  sealWorkerFunction:  AzureFunction  =  async  function (
context:  Context,
req:  HttpRequest
):  Promise<void> {
context.log('HTTP trigger function processed a request.');
const  responseMessage  =  "example";
const  result  =  await  workerExec(req, context);
context.res  = {
// status: 200, /* Defaults to 200 */
body:  responseMessage
};
};
export {sealWorkerFunction};

function.json

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"entryPoint": "sealWorkerFunction",
"scriptFile": "../dist/sealworker/index.js"
}

Output:

enter image description here

Referred this SO Thread.

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6