Azure Functions无法识别函数:src目录结构配置求助
Azure Functions 无法识别src目录下函数的解决办法
问题背景
使用Azure Functions Core Tools 4.0.5095,Function Runtime Version 4.16.5.20396,本地测试及部署后,src目录下的函数均无法被识别。
正常运行的目录结构
host.json package.json myFunc/ - myFunc.ts - function.json
无法运行的目录结构
host.json package.json src/ - myFunc/ -- myFunc.ts -- function.json
已尝试无效操作
- 修改function.json中的
scriptFile指向正确路径,例如:"scriptFile": "../../dist/function1/index.js" - 在local.settings.json中添加
FUNCTIONS_PATHS变量指向src目录 - 将host.json移动到src目录中
有效解决步骤
1. 配置host.json指定函数搜索路径
在根目录的host.json中添加functions字段,明确指定函数所在的src子目录:
{ "version": "2.0", "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[3.*, 4.0.0)" }, "functions": ["src/*"] }
2. 修正TypeScript编译路径与function.json映射
确保tsconfig.json的outDir设置为根目录下的dist,例如:
{ "compilerOptions": { "outDir": "./dist", // 其他编译配置... } }
同时对应src下函数的function.json中,scriptFile路径要指向编译后的文件,比如src/myFunc/function.json:
{ "scriptFile": "../dist/src/myFunc/myFunc.js", "bindings": [ // 绑定配置... ] }
3. 正确设置local.settings.json的FUNCTIONS_PATHS
若使用该变量,确保路径格式与操作系统匹配,且为根目录相对路径:
{ "IsEncrypted": false, "Values": { "FUNCTIONS_WORKER_RUNTIME": "node", "FUNCTIONS_PATHS": "./src" } }
4. 清理重建并重启宿主
- 执行
func clean清理旧构建文件 - 执行
npm run build重新编译代码 - 用
func start --verbose重启本地函数宿主,验证是否识别到src下的函数
内容的提问来源于stack exchange,提问作者Jacob Caron
相关产品推荐
相关产品推荐

