簡體   English   中英

Visual Studio代碼node.js調試:“連接失敗”錯誤

[英]Visual Studio Code node.js debugging: “Connection failed” error

我完全遵循官方指南: https//code.visualstudio.com/Docs/nodejs
在指南的最后:

“...然后按F5開始調試”

我收到以下錯誤:

錯誤連接失敗

我使用Debian Jessie。

我在GNU / Linux Ubuntu 12.04 LTS x64上運行VSCode v0.3.0。


我可以使用內置的VSCode調試器並使用VSCode連接到以調試模式運行的節點進程。

你提到你正在運行debian / jessie GNU / LinuxExpress和Node列在你的標簽中,所以以下內容可能會有所幫助。

通過啟動系統監視器類型應用程序(或您選擇的應用程序或命令行工具) 確保您沒有任何與連接沖突的正在運行的節點進程 ,並終止可能尚未正確退出的任何節點或nodejs進程。

仔細檢查Mono的安裝位置,它的版本是v3.12或更高版本(如果為vNext ASP.net 5開發,則為v4.0.1或更高版本)。

您可以使用任何您喜歡的方法安裝Mono,只要它的版本是v3.12或更高版本。 我選擇在單選項目下從/ opt下載,編譯和安裝Mono。

15:15:34 ツ gjsmith3rd@DV7:~ >which mono /opt/mono/mono-4.0.1/bin/mono

15:15:38 ツ gjsmith3rd@DV7:~ >mono --version Mono JIT compiler version 4.0.1 (tarball Wed Jun 3 09:11:07 CDT 2015) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. 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確保正在調試的應用程序是節點: “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

您現在可以使用node命令行繼續調試過程。

```

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啟動調試器,方法是使用VSCode調試下拉菜單並選擇已配置的JS或Node應用程序並按下調試器播放按鈕。

單擊VSCode調試器中的綠色播放按鈕 ,它應該在附加到進程時打開一個列出調試端口的終端。

Debugger listening on port 38569

如果一切順利,您現在應該能夠使用第二個播放(繼續)按鈕(繼續,跳過,步入,退出和停止)使用VSCode中的調試器控件啟動節點應用程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM