简体   繁体   English

无法使用 Visual Studio Code 调试 Azure JavaScript Function

[英]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:环境:

  • NodeJS v16.x installed安装了 NodeJS v16.x
  • Azure Functions Extensions installed Azure 已安装功能扩展
  • Azure Functions Core Tools 4.x installed Azure 已安装 Functions Core Tools 4.x

Problem:问题:

I created one sample azure function. When running the app with f5 it shows the following error我创建了一个示例 azure function。当使用 f5 运行应用程序时,它显示以下错误

错误图片 1

I removed extension bundle configuration from the host.json and tried again.我从host.json中删除了扩展包配置,然后重试。 This time, I got the following error这次,我收到以下错误

错误图片2

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:先决条件:

  1. Install VS Code and Install the Azure Account , Azure Functions , Azure Storage , Azurite , Extension from Extensions Menu and Sign-in to Azure Account from VS Code.安装VS Code并安装Azure 帐户Azure 功能Azure 存储Azurite 、扩展菜单中的扩展以及从 VS Code登录Azure 帐户。
  2. Download and Install NodeJS Version 14 (and 16 is in preview I guess), Source: https://nodejs.org/en/download/ and https://phoenixnap.com/kb/install-node.js-npm-on-windows下载并安装NodeJS版本 14(我猜 16 是预览版),来源: https://nodejs.org/en/download/https://phoenixnap.com/kb/install-node.js-npm-on -视窗
  1. 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 存储模拟器:

    • Select the Start button or press the Windows key. Select开始按钮或按Windows键。
    • Begin typing Azure Storage Emulator .开始输入Azure Storage Emulator
    • Select the emulator from the list of displayed applications. Select 显示的应用程序列表中的模拟器。
    • Type Start > Enter and Close the Window.键入Start > Enter 并关闭 Window。
  2. 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 命令检查版本。

  3. Install the Azure CLI from the source and PowerShell Module from the source .安装Azure CLI ,从 安装PowerShell 模块

  4. Follow this prerequisite check before going to the IDE (VS Code/Visual Studio).在转到 IDE (VS Code/Visual Studio) 之前,请遵循此先决条件检查


Steps for running the Azure Functions with/without debugging:使用/不使用调试运行 Azure 函数的步骤:

  1. Created the workspace folder in the file explorer and opened VS Code from that folder path.在文件资源管理器中创建工作区文件夹并从该文件夹路径打开 VS Code。
  2. Created Azure Functions Project of JavaScript Stack using Azure Functions extension.使用 Azure 功能扩展创建 Azure 功能项目 JavaScript 堆栈。 Here is the boilerplate code which is not modified:这是未修改的样板代码:

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)"
}
}
  • No need to remove the extension bundles from 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 DebuggingRun without Debugging ,我在没有启动 VS 代码的情况下运行它,它在本地成功运行。

在此处输入图像描述

To Debug the Code:调试代码:

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 ,几个解决步骤是:

  • Use Azure Storage emulator in local development and testing purpose.在本地开发和测试目的中使用Azure 存储模拟器
  • Make Sure You have the latest version of Azure Functions Core Tools along with old if you have (You can install multiple version of AF Core Tools and use according to the requirement).确保您拥有最新版本的 Azure Functions Core Tools以及旧版本(您可以安装多个版本的 AF Core Tools 并根据需要使用)。
  • In local.settings.json , value of 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.

相关问题 从 Visual Studio 2022 调试 Azure Function 应用程序 - Debug Azure Function App from Visual Studio 2022 无法使用 Visual Studio 发布 Azure Function:禁用创建按钮 - Publishing Azure Function using Visual Studio not possible: Create button disabled 如何在 Visual Studio 中使用主机密钥授权创建 azure function? - How can I create an azure function with Host Key authorization in Visual Studio? Java 中的 FunctionApp:通过 Visual Studio Code 调试 - ConnectException - FunctionApp in Java: debug via Visual Studio Code - ConnectException Azure function 在 visual Studio 本地运行时可以访问 Key Vault 但在门户上运行时不能 - Azure function can access Key Vault when run locally in visual Studio but not when run on the portal 我无法使用 Visual Studio 2019 中的 Google Cloud Platform 工具将 App Engine 应用程序发布到 GCloud - I can't publish a App Engine application to GCloud using the Google Cloud Platform tools in Visual Studio 2019 了解Visual Studio中Azure function blob模板的步骤 - Understanding steps of the Azure function blob template in Visual Studio 我们可以从 intellij 调试部署的 azure function 吗? - Can we debug deployed azure function from intellij? 使用 Visual Studio 时看不到 Azure 数据库表 - Cannot see Azure DB tables when using Visual Studio azure 中的 visual studio kube.netes 项目 503 错误 - visual studio kubernetes project 503 error in azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM