-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debug Node.js with ES6 #34615
Comments
Can you set |
Should I put here is the launch.json
after I hit start debugging, debug console prints different content, sometimes prints Content 1, sometimes prints Content 2 (in both cases, the last 2 breakpoints are enabled) Content 1
Content 2
I find that it has no differences whether I set Thanks! |
That's right, when you set that, it prints
please upload that log |
Just out of curiosity, why are you using babel / source maps for ES6 when you are using Node.js 8.5? |
I know that Node.js 8.5 supports the ES6 modules. But to use I am no sure whether these extra steps will still be needed or not in the future. And also, I want to keep the extension And I am just new to Node.js, I don't know if this is a good practice. If you have any instructions for beginners like me, please let me know. Thanks! |
The breakpoints aren't hit because vscode doesn't know where to set the breakpoints until the scripts are already loaded. By the time it loads the sourcemaps, the code in those files has already run. If you set the The error is a debug adapter bug. |
It works, thanks! |
@monsoir would you mind posting resulting configuration and any extra steps you needed to take? What I still don't understand is how you were able to debug ECMAScript modules in the editor while using |
Actually, because the module feature is not supported in Node 8.5 as other ES6 features, I do not debug the ES6 code directly in the editor. I use Babel to compile the ES6 code to JavaScript code which can run directly in Node 8.5. As a result, the code using module feature is compiled to the code which can run directly in Node 8.5. And the code I debug in the editor is the compiled code, not the source code written in ES6. But with some additional configurations, you can set breakpoints in ES6 code directly, editor will do the rest of the work. And here is some steps to setup the debug environment
In the package.json file, add the code below to the
things should be noticed:
Before debugging the code, you should run the command to compile the ES6 source code
Actually, I have recorded these steps, but it is written in my native language Chinese. But there are some screenshots that may help. 👉 The link |
I understand that for the ES6+ you went with Babel to pull off debugging inside editor. For a reason I also thought that this issue’s target was a sceneraio leveraging only ES modules from the specs. For that, there seems to be another issue open. |
Below is my config bit, for cases where you’d like to debug a whatever module (entrypoint) that is in editor’s focus. {
"name": "Launch via Babel",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
"runtimeArgs": ["--presets", "env"],
"program": "${file}"
} |
Thanks to @felicio , show my config below, and all going well:
yarn init -y
yarn add babel-cli babel-core babel-preset-env --dev and edit {
"presets": ["env"]
}
{
"name": "node",
"version": "1.0.0",
"description": "尝试玩一玩",
"main": "index.js",
"author": "scue",
"license": "MIT",
"scripts": {
"start": "babel-node index.js",
"debug": "babel-node debug index.js"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1"
}
}
screenshot: |
I am using Visual Studio Code to debug a Node.js program which is coded with ES6.
I use babel to compile the ES6 to ES5, and everything works fine, code works fine when I run it without debugging.
When it comes to debug, a problem shows up.
There are 3 files:
index.js
imported.js
imported2.js
and here is my launch.js
I am using source map, so that the breakpoints can stop at the source file.
I put 3 breakpoints in the program:
const h = hello();
return 'hello world';
return 'hello world again';
When I enable all 3 breakpoints, all breakpoints works fine, when I disable the first breakpoints, something wrong happens, debug console prints:
It seems the program works fine, but the breakpoints do not take effect.
How could I make the breakpoints works when I just enable the last two breakpoints?
I am using:
node -v v8.5.0
The text was updated successfully, but these errors were encountered: