Azure Function Node.js V3部署Zip包后无函数显示问题排查
问题:Linux环境下Node.js Azure Function V3模型Zip部署后无函数显示
我使用Linux环境的Azure Function Node.js,采用V3编程模型,按相关文档操作后,Zip部署完成且存储账户site/wwwroot目录代码上传正确,但Azure Function App门户中无任何函数显示。
项目信息
项目结构
<root-directory> ├── README.md ├── dist ├── azure_function.zip ├── bin ├── dependencies ├── host.json ├── local.settings.json ├── node_modules ├── package-lock.json ├── package.json ├── sealworker │ ├── constants │ ├── errors │ ├── function.json │ ├── index.ts │ ├── interfaces │ ├── sample.dat │ ├── sealworkerfunction.ts │ ├── 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" } ], "scriptFile": "../dist/sealworker/index.ts" }
index.ts
import { AzureFunction, Context, HttpRequest } from "@azure/functions"; import { workerExec } from "./worker"; const httpTrigger: AzureFunction = async function ( context: Context, req: HttpRequest ): Promise<void> { 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 x = req.body; context.log("x: ", x); context.res = { // status: 200, /* Defaults to 200 */ body: responseMessage, }; }; export default httpTrigger;
host.json
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[3.*, 4.0.0)" } }
排查方向及解决方法
- 修正
scriptFile路径:Linux环境路径区分大小写,且Azure Functions运行时仅能执行编译后的.js文件。将function.json中的scriptFile修改为../dist/sealworker/index.js,同时确认TypeScript编译后dist目录下存在该文件。 - 确保编译步骤完成:部署前必须执行
npm run build(需在package.json中配置编译脚本,如"build": "tsc"),确保dist目录生成完整的编译产物,且zip包包含该目录的全部内容。 - 核对运行时版本:在Azure门户的函数应用配置中,确认
FUNCTIONS_EXTENSION_VERSION设置为~3,匹配V3编程模型要求。 - 检查zip包结构:zip包根目录需直接包含
host.json、package.json以及sealworker、dist等目录,不能将整个项目根目录嵌套在zip内部。 - 查看运行日志:在Azure门户的「监测」>「日志」中查看运行时日志,排查是否存在文件路径错误、依赖缺失或编译失败等报错。
- 配置
package.json入口:V3模型下,需在package.json中设置main字段指向正确路径,如"main": "dist/sealworker/index.js",确保运行时能找到函数入口。
内容的提问来源于stack exchange,提问作者Kid_Learning_C
相关产品推荐
相关产品推荐

