I have a nodejs express application, which I'm attempting to bundle with webpack 4 (plus babel 7.1.0). I've followed some of the setup from these two articles:
I can build and run the server once bundled, but I'd like to be able to debug it using VS Code's debug environment.
I've tried the following combination of webpack and vscode config, but it doesn't set breakpoints or let me step into the code.
.vscode/launch.json
{
"type": "node",
"request": "launch",
"name": "bundle-server.js",
"program": "${workspaceFolder}\\bundle-server.js",
"sourceMaps": true,
"smartStep": true,
}
webpack-server.config.js
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
target: "node",
entry: "./server.js",
output: {
path: path.resolve(__dirname, "./"),
filename: "bundle-server.js",
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: "babel-loader"
}
],
},
externals: [nodeExternals()],
devtool: 'inline-source-map',
};
What am I missing? Is it even possible to debug directly from VSCode? I'd like to be able to step over the original source files so I can have a quick debug-edit-rerun loop.
Seems related to this: Debug webpack bundled node ts with Visual Studio Code.
Click the "inspect" link under each script to open a dedicated debugger or the Open dedicated DevTools for Node link for a session that will connect automatically. You can also check out the NiM extension, a handy Chrome plugin that will automatically open a DevTools tab every time you --inspect a script.
Launch configurations# To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file.
To run above scripts, open a terminal and type npm run webpack or select Tasks: Run Task from the Command Palette (Ctrl+Shift+P).
In your launch configs, you are providing output file of webpack as the program
to debug.
To Build:
You can instead use program
as path to your webpack runner. Ex:
"program": "${workspaceFolder}/node_modules/webpack/bin/webpack.js" // Or CLI
And then you should provide the file as an argument you want to run with webpack. Ex:
"args": [
"--config", "./some/dir/webpack.config.js"
]
To Run:
Follow the same procedure with a different program
"program": "${workspaceFolder}/node_modules/webpack-dev-server/bin/webpack-dev-server",
"args": [
"--config",
"webpack-server.config.js",
"--hot",
"--progress"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With