Azure TypeScript函数:无法确定函数入口点

huangapple go评论99阅读模式
英文:

Azure typescript function: Unable to determine function entry point

问题

项目结构:

<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;

错误信息:

结果:失败
异常:Worker 无法加载函数 sealworker: '无法确定函数入口点:sealWorkerFunction。如果导出了多个函数,则必须通过将其命名为'run'或'index',或通过显式命名来指示入口点,使用 'entryPoint' 元数据属性。' 堆栈:错误:Worker 无法加载函数 sealworker: '无法确定函数入口点:sealWorkerFunction。如果导出了多个函数,则必须通过将其命名为'run'或'index',或通过显式命名来指示入口点,使用 'entryPoint' 元数据属性。' 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)

还有,在构建后的 dist/sealworker/index.js 文件中:

"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 worker_1.default(req, context);
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: responseMessage,
        };
    });
};
exports.default = { sealWorkerFunction };
//# sourceMappingURL=index.js.map

我已经按照文档正确配置了 Azure Linux TypeScript Node.js 函数的入口点,但可能有遗漏的地方。

有什么建议吗?

英文:

project structure:

&lt;root-directory&gt;
├── 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:

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

/sealworker/index.ts:

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

const sealWorkerFunction: AzureFunction = async function (
  context: Context,
  req: HttpRequest
): Promise&lt;void&gt; {
  const responseMessage = &quot;example&quot;;
  const result = await workerExec(req, context);

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

export default { sealWorkerFunction };

/sealworker/worker.ts:

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

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

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.<anonymous>
> (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:14945)
> at Generator.next (<anonymous>) 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:

&quot;use strict&quot;;
var __awaiter = (this &amp;&amp; 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[&quot;throw&quot;](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 &amp;&amp; this.__importDefault) || function (mod) {
    return (mod &amp;&amp; mod.__esModule) ? mod : { &quot;default&quot;: mod };
};
Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });
const worker_1 = __importDefault(require(&quot;./worker&quot;));

const sealWorkerFunction = function (context, req) {
    return __awaiter(this, void 0, void 0, function* () {
        const name = req.query.name || (req.body &amp;&amp; req.body.name);
        const responseMessage = name
            ? &quot;Hello, &quot; + name + &quot;. This HTTP triggered function executed successfully.&quot;
            : &quot;This HTTP triggered function executed successfully. Pass a name in the query string or in the req body for a personalized response.&quot;;
        context.log(`Http function processed req for url &quot;${req.url}&quot;`);
        const message = req.body;
        context.log(&quot;type of message: &quot;, typeof message);
        context.log(&quot;message: &quot;, 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?

答案1

得分: 1

最初我也遇到了这个错误,但在我的index.ts文件中进行了**export {sealWorkerFunction}**的修改后,它对我起作用了。

代码:

index.ts

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

function.json

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

输出:

Azure TypeScript函数:无法确定函数入口点

参考了这个SO Thread

英文:

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  &quot;@azure/functions&quot;;
import  workerExec  from  &quot;./worker&quot;;
const  sealWorkerFunction:  AzureFunction  =  async  function (
context:  Context,
req:  HttpRequest
):  Promise&lt;void&gt; {
context.log(&#39;HTTP trigger function processed a request.&#39;);
const  responseMessage  =  &quot;example&quot;;
const  result  =  await  workerExec(req, context);
context.res  = {
// status: 200, /* Defaults to 200 */
body:  responseMessage
};
};
export {sealWorkerFunction};

function.json

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

Output:

Azure TypeScript函数:无法确定函数入口点

Referred this SO Thread.

huangapple
  • 本文由 发表于 2023年8月8日 23:40:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定