在 visual studio 代码中调试不起作用

新手上路,请多包涵

启动配置

{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "port": 5858
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceRoot}/src/app.js",
            "cwd": "${workspaceRoot}"
        }
    ]
}

在 visual studio 代码中调试我的反应代码时出现以下错误。实际上我已经用 node+react 创建了项目,并使用 visual studio 作为 IDE 并想调试我的代码。我已经尝试了很多但无法成功调试我的代码。

 Debugging with legacy protocol because Node.js v6.10.2 was detected.Program path uses differently cased character as file on disk; this might result in breakpoints not being hit.
node --debug-brk=21730 --nolazy src\app.js
    Debugger listening on [::]:21730
    e:\reactjs\reactFacebook\my-app\src\app.js:1
    (function (exports, require, module, __filename, __dirname) { import React, { Component } from 'react';
                                                                  ^^^^^^
    SyntaxError: Unexpected token import
        at createScript (vm.js:56:10)
        at Object.runInThisContext (vm.js:97:10)
        at Module._compile (module.js:542:28)
        at Object.Module._extensions..js (module.js:579:10)
        at Module.load (module.js:487:32)
        at tryModuleLoad (module.js:446:12)
        at Function.Module._load (module.js:438:3)
        at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
        at ontimeout (timers.js:380:14)
        at tryOnTimeout (timers.js:244:5)

原文由 Himanshu Pandey 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 379
1 个回答

我通过在要调试的函数中添加以下代码来解决它:

 debugger;

并开始调试。编码快乐!!

原文由 Aman Verma 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题