Azure Functions项目用npm start启动时无法运行,但用func start可以运行
我有一个项目,它是用这个package.json文件配置的(我这里只粘贴相关部分)
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"clean": "rimraf dist",
"prestart": "npm run clean && npm run build",
"start": "func start",
"test": "jest --coverage"
},
"dependencies": {
"@azure/data-tables": "^13.3.0",
"@azure/event-hubs": "^5.12.2",
"@azure/functions": "^4.0.0",
"@azure/openai": "^2.0.0",
},
这是host.json文件的内容
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
当我运行npm start命令时,项目无法启动,出现如下错误
[2026-03-03T19:32:34.843Z] A host error has occurred during startup operation '9c57a68b-77c9-4f1b-8877-01ac04444ab0'.
[2026-03-03T19:32:34.846Z] Microsoft.Azure.WebJobs.Extensions.EventHubs: Could not load file or assembly 'System.Memory.Data, Version=6.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
[2026-03-03T19:32:34.846Z] .
Value cannot be null. (Parameter 'provider')
[2026-03-03T19:32:34.882Z] Host startup operation has been canceled
但如果我运行命令func start,项目就能正常启动
感谢您的帮助
解决方案
在完成这些更新后
"@azure/data-tables": "^13.3.2",
"@azure/event-hubs": "^5.12.2",
"@azure/functions": "^4.6.0",
现在我可以正常运行npm start
我猜这与全局安装的azure-functions-core-tools版本有关。我是用以下方式安装的
npm install -g azure-functions-core-tools
如果我运行
func --version
它显示4.7.0。没有提及全局版本与项目中本地运行的版本之间的相关性,但它们之间肯定存在某种联系。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。