[英]Can't Debug Azure JavaScript Function using Visual Studio Code
I am using VS code first time and trying to create a azure function with JavaScript language.我第一次使用 VS 代码并尝试使用 JavaScript 语言创建 azure function。 I followed this article .我关注了这篇文章。
Environment:环境:
Problem:问题:
I created one sample azure function. When running the app with f5 it shows the following error我创建了一个示例 azure function。当使用 f5 运行应用程序时,它显示以下错误
I removed extension bundle configuration from the host.json
and tried again.我从host.json
中删除了扩展包配置,然后重试。 This time, I got the following error这次,我收到以下错误
Can anyone please help on me this谁能帮我这个
Update:更新:
host.json主机.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
local.settings.json local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node"
}
}
index.js索引.js
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
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 request body for a personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
}
Here is the workaround I did to run the Azure Functions of JavaScript Stack using Visual Studio Code by following the same documentation given in the question这是我按照问题中给出的相同文档使用 Visual Studio Code 运行 JavaScript Stack 的 Azure 函数的解决方法
Pre-requisites:先决条件:
node -v
and npm -v
.使用命令node -v
和npm -v
从命令提示符验证安装。Install the Azure Storage Emulator (it is deprecated but still using for local development and testing) from here by clicking on the standalone installer.单击独立安装程序从此处安装Azure 存储模拟器(已弃用但仍用于本地开发和测试)。 -After Installing the Azure Storage Emulator, make sure it is running. - 安装 Azure 存储模拟器后,确保它正在运行。 If it is shutdown, then run it manually.如果它已关闭,则手动运行它。 To start the Azure Storage Emulator:要启动 Azure 存储模拟器:
Azure Storage Emulator
.开始输入Azure Storage Emulator
。Start
> Enter and Close the Window.键入Start
> Enter 并关闭 Window。 Install the Azure Functions Core Tools v3 as well as v4 used for both Old Version and New Version Stack Development from the source and check the version using func --versio
n command from command prompt.从源安装用于旧版本和新版本堆栈开发的Azure Functions Core Tools v3 和 v4,并在命令提示符下使用func --versio
n 命令检查版本。
Install the Azure CLI from the source and PowerShell Module from the source .从源安装Azure CLI ,从 源安装PowerShell 模块。
Follow this prerequisite check before going to the IDE (VS Code/Visual Studio).在转到 IDE (VS Code/Visual Studio) 之前,请遵循此先决条件检查。
Index.js索引.js
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
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 request body for a personalized response.";
context.res = {
// status: 200, /* Defaults to 200 */
body: responseMessage
};
}
local.settings.json local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "node"
}
}
host.json主机.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
host.json
无需从host.json
中删除扩展包To Run the Function, go to Run Menu > Select either of options Start Debugging
or Run without Debugging
and I have run this without starting the VS Code, it runs successful in locally.要运行 Function、go 到运行菜单 > Select 选项Start Debugging
或Run without Debugging
,我在没有启动 VS 代码的情况下运行它,它在本地成功运行。
Put a breakpoint at any line of the code and select the Start Debugging
option from the Run
Menu在代码的任意行和 select 中放置一个断点从Run
菜单Start Debugging
选项
Note: For the errors like: A host error has occurred during startup operation
, Value cannot be null
, few resolution steps were:注意:对于类似的错误: A host error has occurred during startup operation
, Value cannot be null
,几个解决步骤是:
AzureWebJobsStorage
is empty by default but if we're using the project locally, it is better to use like "AzureWebJobsStorage": "UseDevelopmentStorage=true"
在local.settings.json中, AzureWebJobsStorage
的值默认为空,但如果我们在本地使用该项目,最好使用 like "AzureWebJobsStorage": "UseDevelopmentStorage=true"
You can download the above project from my GitHub Repository .您可以从我的GitHub Repository下载上述项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.