VSCode在调试适配器中调试带有ES6未处理错误的Node.js

时间:2017-09-19 06:38:13

标签: javascript node.js debugging visual-studio-code

我正在使用Visual Studio Code来调试用ES6编码的Node.js程序。

我使用babel将ES6编译为ES5,一切正常,在没有调试的情况下运行代码时工作正常。

在调试时,会出现问题。

有3个文件:

index.js

import hello from './imported';
import hello2 from './imported2';

const h = hello();
const h2 = hello2()

console.log(h);
console.log(h2);

imported.js

function hello() {
    return 'hello world';
};

export default hello;

imported2.js

function hello2() {
    return 'hello world again';
}

export default hello2;

这是我的launch.js

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "port": 5858
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceRoot}/build/index.js",
            "sourceMaps": true
        }
    ]
}

是的,我正在使用源映射,以便断点可以停在源文件中。

我在程序中放了3个断点:

  1. index.js const h = hello();
  2. imported.js return 'hello world';
  3. imported2.js return 'hello world again';
  4. 当我启用所有3个断点时,所有断点都正常工作,当我禁用第一个断点时,出现错误,调试控制台打印:

    Debugging with inspector protocol because Node.js v8.5.0 was detected.
    node --inspect=38607 --debug-brk build/index.js 
    Debugger listening on ws://127.0.0.1:38607/7cf119cf-beb5-4105-84f3-880f44c9fe00
    Debugger attached.
    hello world
    hello world again
    ******** Unhandled error in debug adapter - Unhandled promise rejection: Error: not opened
        at LoggingSocket.send (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/ws/lib/WebSocket.js:219:16)
        at LoggingSocket.send (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/vscode-chrome-debug-core/out/src/chrome/chromeConnection.js:43:20)
        at Client._sendQueuedRequests (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/noice-json-rpc/lib/noice-json-rpc.js:82:30)
        at Client._send (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/noice-json-rpc/lib/noice-json-rpc.js:76:14)
        at Promise (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/noice-json-rpc/lib/noice-json-rpc.js:100:18)
        at Promise (<anonymous>)
        at Client.call (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/noice-json-rpc/lib/noice-json-rpc.js:98:16)
        at Proxy.target.(anonymous function) (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/noice-json-rpc/lib/noice-json-rpc.js:140:53)
        at NodeDebugAdapter.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/nod[...]
    ******** Unhandled error in debug adapter - Unhandled promise rejection: Error: not opened
        at LoggingSocket.send (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/ws/lib/WebSocket.js:219:16)
        at LoggingSocket.send (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/vscode-chrome-debug-core/out/src/chrome/chromeConnection.js:43:20)
        at Client._sendQueuedRequests (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/noice-json-rpc/lib/noice-json-rpc.js:82:30)
    

    程序似乎工作正常,但断点不起作用。

    当我启用最后两个断点时,如何使断点起作用?

    我正在使用:

    • Visual Studio Code Version 1.16.1(1.16.1)
    • node -v v8.5.0

1 个答案:

答案 0 :(得分:0)

问题已解决https://github.com/Microsoft/vscode/issues/34615

快速查看,这是关键:

  

如果将启动配置的outFiles属性设置为指向磁盘上的那些文件,那么它应该能够提前加载源映射。