node.js - 调试 nuxt + Express - 断点未命中

标签 node.js express visual-studio-code webstorm nuxt.js

我正在尝试开始使用 nuxt + express。我有这里的代码:https://github.com/nuxt/express ,使用 npm run dev 运行良好。我想调试 API 代码。

在 users.js 文件中:

import { Router } from 'express'

var router = Router()

// Mock Users
const users = [
  { name: 'Alexandre' },
  { name: 'Sébastien' }
]

/* GET users listing. */
router.get('/users', function (req, res, next) {
  res.json(users)
})

/* GET user by ID. */
router.get('/users/:id', function (req, res, next) {
  var id = parseInt(req.params.id)
  if (id >= 0 && id < users.length) {
    res.json(users[id])
  } else {
    res.sendStatus(404)
  }
})

export default router

我在两个 get 方法中都设置了断点。我尝试过使用 WebStorm 和 Visual Studio Code,但在这两种情况下都没有命中断点。

我的 launch.json 文件如下所示:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceRoot}\\build\\main.js"
    }
  ]
}

和 package.json:

{
  "name": "learn-nuxt",
  "version": "1.0.0",
  "description": "Nuxt.js project",
  "author": "naveed",
  "private": true,
  "scripts": {
    "dev": "backpack",
    "build": "nuxt build && backpack build",
    "start": "cross-env NODE_ENV=production node build/main.js",
    "precommit": "npm run lint",
    "lint": "eslint --ext .js,.vue --ignore-path .gitignore ."
  },
  "dependencies": {
    "axios": "^0.16.1",
    "backpack-core": "^0.3.0",
    "cross-env": "^4.0.0",
    "express": "^4.14.0",
    "nuxt": "~0.10.6",
    "source-map-support": "^0.4.14"
  },
  "devDependencies": {
    "babel-eslint": "^7.1.1",
    "backpack-core": "^0.3.0",
    "eslint": "^3.13.1",
    "eslint-config-standard": "^10.2.1",
    "eslint-loader": "^1.7.1",
    "eslint-plugin-html": "^2.0.1",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-node": "^4.2.2",
    "eslint-plugin-promise": "^3.4.0",
    "eslint-plugin-standard": "^3.0.1"
  }
}

这是我在 VS Code 控制台中看到的:

Debugging with legacy protocol because Node.js v7.4.0 was detected.
node --debug-brk=42131 --nolazy build\main.js 
Debugger listening on 127.0.0.1:42131
Server listening on 127.0.0.1:3000
 DONE  Compiled successfully in 5591ms9:28:41 PM
> Open http://127.0.0.1:3000

最佳答案

我发现添加

"protocol": "inspector"

launch.json 中的配置修复了这个问题并允许命中断点。

关于node.js - 调试 nuxt + Express - 断点未命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43860083/

相关文章:

javascript - 在 Titan Appcelator ios 中实现 otr.js?

node.js - npm WARN checkPermissions 缺少写入权限

javascript - Express 路由器/功能的模块导出

node.js - 本地主机、[::1] 和 etc/hosts 中的映射主机可以工作,但 127.0.0.1 不能

visual-studio-code - 在vscode中,我只能在按下alt键时获得悬停信息吗?

node.js - stripe.customers.retrieve 导致问题,因为它现在正在返回 Stripe.Customer | Stripe .DeletedCustomer

node.js - 在 Angular/w Electron 中在哪里执行初始化函数?

angularjs - router.post返回错误 "undefined is not a function"。使用mongo和express.js

visual-studio - Visual Studio Code 和 Visual Studio 之间有什么区别?

azure - VSCode 中的 Python Azure Function (HTTPTrigger) 调试未正确启动 Func Host Start