Aller au contenu principal
Version: 3.0.0


This section describes how to debug a Midway project in a common editor.

Debugging in VSCode

Method 1: Use JavaScript Debug Teminal

Pull out under the VSCode terminal and hide a JavaScript Debug Terminal. Click on it and the created terminal will have its own debugging capability. image.png

If you enter any command, Debug is automatically enabled. For example, after you enter npm run dev. image.png

Method 2: Configure debug files

Create a startup file for vscode. image.png Select any one and create a .vscode/launch.json file, image.png

Copy the following.

// Use IntelliSense to understand related attributes.
// Hover to view a description of an existing attribute.
// For more information, please visit:
"version": "0.2.0 ",
"configurations": [{
"name": "Midway Local ",
"type": "node ",
"request": "launch ",
"cwd": "${workspaceRoot} ",
"runtimeExecutable": "npm ",
"windows": {
"runtimeExecutable": "npm.cmd"
"runtimeArgs": [
"run ",
"env": {
"NODE_ENV": "local"
"console": "integratedTerminal ",
"protocol": "auto ",
"restart": true
"port": 7001
"autoAttachChildProcesses": true

Just start the breakpoint. image.png

Debugging in WebStorm/Idea

Start configuring IDE. image.png

Configure the npm command. image.png

After you select package.json, drop down and select Scrips, which is the command in the scripts configured in package.json. Select the command you want, such as dev or test. image.png

Debugging can be performed after the code breakpoint. image.png

Debugging in Chrome

If you use vim or other code editors, you can use this method, through the dev command of @midwayjs/cli, add the --debug parameter to enable debug mode, you can use chrome devtools for single-step code debugging :

69456694-513D-4388-B52F-001562D4A520.png You can use chrome:// inspect/ to open the nodejs devtools for breakpoint debugging: image.png image.png You can also directly open the link of the devtools protocol output from the command line through the chrome browser, add a breakpoint to the corresponding code and debug it: 10016148-385E-46A4-8B3A-0A0110BECD18.png