在指南的最后一步:
时,我出现了如下错误:"...然后按 F5 启动调试"
我使用的是Debian Jessie系统。Error Connection failed
时,我出现了如下错误:"...然后按 F5 启动调试"
我使用的是Debian Jessie系统。Error Connection failed
您提到您正在运行debian/jessie GNU/Linux,并且在您的标签中列出了Express和Node,因此以下内容可能会有所帮助。
确保没有运行任何node进程会与连接冲突,方法是启动系统监视器类型应用程序(或您选择的应用程序或命令行工具),并终止可能没有正确退出的任何node或nodejs进程。
仔细检查您的Mono安装位置以及其版本为v3.12或更高版本(如果开发vNext ASP.net 5,则为v4.0.1或更高版本)。
您可以使用任何方法安装Mono,只要它的版本是v3.12或更高版本即可。我选择从mono-project下载、编译并在我的分发版中安装Mono到/opt下。
15:15:34 ツ gjsmith3rd@DV7:~ >which mono
/opt/mono/mono-4.0.1/bin/mono
15:15:38 ツ gjsmith3rd@DV7:~ >mono --version
Mono JIT 编译器版本 4.0.1 (tarball Wed Jun 3 09:11:07 CDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc 和贡献者。 www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen
您需要记录 Mono 的安装位置以进行环境配置。 在我的情况下,位置为 /opt/mono/mono-4.0.1/*
。 您需要更改此位置以反映您的实际环境。 一旦确定了正确的版本和安装位置,请确保在您的.bashrc、.bash_profile或相关 shell 环境中为您的发行版正确配置了安装的环境变量。
```
export PATH=/opt/mono/mono-4.0.1/bin:$PATH
export MONO_LOG_LEVEL=debug
export MONO_LOG_MASK=asm
export LD_LIBRARY_PATH=/opt/mono/mono-4.0.1/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/opt/mono/mono-4.0.1/pkgconfig
export MONO_PATH=/opt/mono/mono-4.0.1/lib
```
再次提醒,路径需要反映您环境中的位置。如果您对环境进行任何更改,请源化您的shell或注销并重新登录。
$ source .bashrc
启动VSCode或关闭并重新启动VSCode。
在您的VSCode调试配置文件(单击调试中的齿轮图标获取启动配置)launch.json中,确保您正在调试的应用程序是node: "type": "node"。
```
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch server.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "server.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "10.0.0.57",
// Port to attach to.
"port": 5858
}
]
}
```
保存任何更改。
如果您想附加到正在运行的节点进程,则从应用程序目录中的命令行启动节点应用程序。
$node debug appname.js
现在,您可以使用节点命令行继续调试过程。
```
17:37:51 ツ gjsmith3rd@DV7:(master)~/Workspaces/Development/devsandbox >node debug server.js
< Debugger listening on port 5858
debug> . ok
break in server.js:5
3
4 // OpenShift sample Node application
> 5 var express = require('express');
6 var fs = require('fs');
7 // var bootstrap = require("bootstrap");
debug> next
break in server.js:6
4 // OpenShift sample Node application
5 var express = require('express');
> 6 var fs = require('fs');
7 // var bootstrap = require("bootstrap");
8
debug>
```
或者启动VSCode并将调试器附加到正在运行的节点调试过程中。 确保您的VSCode启动配置具有正确配置的attach
条目,并通过选择调试器下拉菜单在VSCode中运行它。 您将需要根据您的要求配置IP和端口。
```
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
```
最后,您应该能够通过使用VSCode调试下拉菜单并选择已配置的JS或Node应用程序,然后按下调试器播放按钮而无需使用命令行来启动调试器。
在您的VSCode调试器中点击绿色播放按钮,它应该会打开一个终端列出调试端口并附加到进程。
Debugger listening on port 38569
如果一切正常,您现在应该能够使用VSCode内的调试器控件使用第二个播放(继续)、跳过、步入、步出和停止按钮来启动节点应用程序。