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

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

Azure typescript function: Unable to determine function entry point

问题

项目结构:

  1. <root-directory>
  2. ├── README.md
  3. ├── dist
  4. ├── bin
  5. ├── dependencies
  6. ├── host.json
  7. ├── local.settings.json
  8. ├── node_modules
  9. ├── package-lock.json
  10. ├── package.json
  11. ├── sealworker
  12. │ ├── constants
  13. │ ├── errors
  14. │ ├── function.json
  15. │ ├── index.ts
  16. │ ├── interfaces
  17. │ ├── sample.dat
  18. │ ├── services
  19. │ ├── utils
  20. │ └── worker.ts
  21. └── tsconfig.json

function.json:

  1. {
  2. "bindings": [
  3. {
  4. "authLevel": "function",
  5. "type": "httpTrigger",
  6. "direction": "in",
  7. "name": "req",
  8. "methods": [
  9. "get",
  10. "post"
  11. ]
  12. },
  13. {
  14. "type": "http",
  15. "direction": "out",
  16. "name": "res"
  17. }
  18. ],
  19. "entryPoint": "sealWorkerFunction",
  20. "scriptFile": "../dist/sealworker/index.js"
  21. }

/sealworker/index.ts:

  1. import { AzureFunction, Context, HttpRequest } from "@azure/functions";
  2. import workerExec from "./worker";
  3. const sealWorkerFunction: AzureFunction = async function (
  4. context: Context,
  5. req: HttpRequest
  6. ): Promise<void> {
  7. const responseMessage = "example";
  8. const result = await workerExec(req, context);
  9. context.res = {
  10. // status: 200, /* Defaults to 200 */
  11. body: responseMessage,
  12. };
  13. };
  14. export default { sealWorkerFunction };

/sealworker/worker.ts:

  1. import "dotenv/config";
  2. import "reflect-metadata";
  3. import { HttpRequest, Context } from "@azure/functions";
  4. const workerExec = async (req: HttpRequest, context: Context) => {
  5. context.log("start....");
  6. const message = req.body;
  7. context.log("message: ", message);
  8. return { result: "dummy" };
  9. };
  10. 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 文件中:

  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __importDefault = (this && this.__importDefault) || function (mod) {
  12. return (mod && mod.__esModule) ? mod : { "default": mod };
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. const worker_1 = __importDefault(require("./worker"));
  16. const sealWorkerFunction = function (context, req) {
  17. return __awaiter(this, void 0, void 0, function* () {
  18. const name = req.query.name || (req.body && req.body.name);
  19. const responseMessage = name
  20. ? "Hello, " + name + ". This HTTP triggered function executed successfully."
  21. : "This HTTP triggered function executed successfully. Pass a name in the query string or in the req body for a personalized response.";
  22. context.log(`Http function processed req for url "${req.url}"`);
  23. const message = req.body;
  24. context.log("type of message: ", typeof message);
  25. context.log("message: ", message);
  26. const result = yield worker_1.default(req, context);
  27. context.res = {
  28. // status: 200, /* Defaults to 200 */
  29. body: responseMessage,
  30. };
  31. });
  32. };
  33. exports.default = { sealWorkerFunction };
  34. //# sourceMappingURL=index.js.map

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

有什么建议吗?

英文:

project structure:

  1. &lt;root-directory&gt;
  2. ├── README.md
  3. ├── dist
  4. ├── bin
  5. ├── dependencies
  6. ├── host.json
  7. ├── local.settings.json
  8. ├── node_modules
  9. ├── package-lock.json
  10. ├── package.json
  11. ├── sealworker
  12. ├── constants
  13. ├── errors
  14. ├── function.json
  15. ├── index.ts
  16. ├── interfaces
  17. ├── sample.dat
  18. ├── services
  19. ├── utils
  20. └── worker.ts
  21. └── tsconfig.json

function.json:

  1. {
  2. &quot;bindings&quot;: [
  3. {
  4. &quot;authLevel&quot;: &quot;function&quot;,
  5. &quot;type&quot;: &quot;httpTrigger&quot;,
  6. &quot;direction&quot;: &quot;in&quot;,
  7. &quot;name&quot;: &quot;req&quot;,
  8. &quot;methods&quot;: [
  9. &quot;get&quot;,
  10. &quot;post&quot;
  11. ]
  12. },
  13. {
  14. &quot;type&quot;: &quot;http&quot;,
  15. &quot;direction&quot;: &quot;out&quot;,
  16. &quot;name&quot;: &quot;res&quot;
  17. }
  18. ],
  19. &quot;entryPoint&quot;: &quot;sealWorkerFunction&quot;,
  20. &quot;scriptFile&quot;: &quot;../dist/sealworker/index.js&quot;
  21. }

/sealworker/index.ts:

  1. import { AzureFunction, Context, HttpRequest } from &quot;@azure/functions&quot;;
  2. import workerExec from &quot;./worker&quot;;
  3. const sealWorkerFunction: AzureFunction = async function (
  4. context: Context,
  5. req: HttpRequest
  6. ): Promise&lt;void&gt; {
  7. const responseMessage = &quot;example&quot;;
  8. const result = await workerExec(req, context);
  9. context.res = {
  10. // status: 200, /* Defaults to 200 */
  11. body: responseMessage,
  12. };
  13. };
  14. export default { sealWorkerFunction };

/sealworker/worker.ts:

  1. import &quot;dotenv/config&quot;;
  2. import &quot;reflect-metadata&quot;;
  3. import { HttpRequest, Context } from &quot;@azure/functions&quot;;
  4. const workerExec = async (req: HttpRequest, context: Context) =&gt; {
  5. context.log(&quot;start....&quot;);
  6. const message = req.body;
  7. context.log(&quot;message: &quot;, message);
  8. return { result: &quot;dummy&quot; };
  9. };
  10. 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:

  1. &quot;use strict&quot;;
  2. var __awaiter = (this &amp;&amp; this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator[&quot;throw&quot;](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __importDefault = (this &amp;&amp; this.__importDefault) || function (mod) {
  12. return (mod &amp;&amp; mod.__esModule) ? mod : { &quot;default&quot;: mod };
  13. };
  14. Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });
  15. const worker_1 = __importDefault(require(&quot;./worker&quot;));
  16. const sealWorkerFunction = function (context, req) {
  17. return __awaiter(this, void 0, void 0, function* () {
  18. const name = req.query.name || (req.body &amp;&amp; req.body.name);
  19. const responseMessage = name
  20. ? &quot;Hello, &quot; + name + &quot;. This HTTP triggered function executed successfully.&quot;
  21. : &quot;This HTTP triggered function executed successfully. Pass a name in the query string or in the req body for a personalized response.&quot;;
  22. context.log(`Http function processed req for url &quot;${req.url}&quot;`);
  23. const message = req.body;
  24. context.log(&quot;type of message: &quot;, typeof message);
  25. context.log(&quot;message: &quot;, message);
  26. const result = yield (0, worker_1.default)(req, context);
  27. context.res = {
  28. // status: 200, /* Defaults to 200 */
  29. body: responseMessage,
  30. };
  31. });
  32. };
  33. exports.default = { sealWorkerFunction };
  34. //# 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

  1. import { AzureFunction, Context, HttpRequest } from &quot;@azure/functions&quot;;
  2. import workerExec from &quot;./worker&quot;;
  3. const sealWorkerFunction: AzureFunction = async function (
  4. context: Context,
  5. req: HttpRequest
  6. ): Promise&lt;void&gt; {
  7. context.log(&#39;HTTP trigger function processed a request.&#39;);
  8. const responseMessage = &quot;example&quot;;
  9. const result = await workerExec(req, context);
  10. context.res = {
  11. // status: 200, /* Defaults to 200 */
  12. body: responseMessage
  13. };
  14. };
  15. export {sealWorkerFunction};

function.json

  1. {
  2. &quot;bindings&quot;: [
  3. {
  4. &quot;authLevel&quot;: &quot;function&quot;,
  5. &quot;type&quot;: &quot;httpTrigger&quot;,
  6. &quot;direction&quot;: &quot;in&quot;,
  7. &quot;name&quot;: &quot;req&quot;,
  8. &quot;methods&quot;: [
  9. &quot;get&quot;,
  10. &quot;post&quot;
  11. ]
  12. },
  13. {
  14. &quot;type&quot;: &quot;http&quot;,
  15. &quot;direction&quot;: &quot;out&quot;,
  16. &quot;name&quot;: &quot;res&quot;
  17. }
  18. ],
  19. &quot;entryPoint&quot;: &quot;sealWorkerFunction&quot;,
  20. &quot;scriptFile&quot;: &quot;../dist/sealworker/index.js&quot;
  21. }

输出:

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

  1. import { AzureFunction, Context, HttpRequest } from &quot;@azure/functions&quot;;
  2. import workerExec from &quot;./worker&quot;;
  3. const sealWorkerFunction: AzureFunction = async function (
  4. context: Context,
  5. req: HttpRequest
  6. ): Promise&lt;void&gt; {
  7. context.log(&#39;HTTP trigger function processed a request.&#39;);
  8. const responseMessage = &quot;example&quot;;
  9. const result = await workerExec(req, context);
  10. context.res = {
  11. // status: 200, /* Defaults to 200 */
  12. body: responseMessage
  13. };
  14. };
  15. export {sealWorkerFunction};

function.json

  1. {
  2. &quot;bindings&quot;: [
  3. {
  4. &quot;authLevel&quot;: &quot;function&quot;,
  5. &quot;type&quot;: &quot;httpTrigger&quot;,
  6. &quot;direction&quot;: &quot;in&quot;,
  7. &quot;name&quot;: &quot;req&quot;,
  8. &quot;methods&quot;: [
  9. &quot;get&quot;,
  10. &quot;post&quot;
  11. ]
  12. },
  13. {
  14. &quot;type&quot;: &quot;http&quot;,
  15. &quot;direction&quot;: &quot;out&quot;,
  16. &quot;name&quot;: &quot;res&quot;
  17. }
  18. ],
  19. &quot;entryPoint&quot;: &quot;sealWorkerFunction&quot;,
  20. &quot;scriptFile&quot;: &quot;../dist/sealworker/index.js&quot;
  21. }

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:

确定