gpt4 book ai didi

javascript - VSCode 调试 Node.js,调试适配器中存在 ES6 未处理错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:00:11 25 4
gpt4 key购买 nike

我正在使用 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);

导入的.js

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

export default hello;

导入2.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';

当我启用所有 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 代码版本 1.16.1 (1.16.1)
  • Node -v v8.5.0

最佳答案

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

为了快速浏览,关键是:

If you set the outFiles property of your launch config to point toward those files on disk, then it should be able to load the sourcemaps ahead of time.

关于javascript - VSCode 调试 Node.js,调试适配器中存在 ES6 未处理错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46293527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com