SourceMaps使用VSCode Gatsy调试错误

时间:2018-06-03 04:08:55

标签: visual-studio-code xdebug source-maps gatsby

我试图设置VSCode以便能够调试Gatsby代码。 我是Javascript源码图的新手,这似乎是导致问题的原因。

我在发布时看到以下错误:

Cannot launch program "c:\Gatsby\myprogram\node_modules\.bin\gatsby" because corresponding Javascript cannot be found.

我验证了错误中gatsby文件的路径存在。

这是我用于launch.json的文件:

  "version": "0.2.0",
  "configurations": [
    {
    "name": "Launch",
    "type": "node",
    "request": "launch",
    "protocol": "inspector",
    "program": "${workspaceRoot}/node_modules/.bin/gatsby",
    "args": ["develop", "-p", "7777"],
    "stopOnEntry": false,
    "cwd": "${workspaceRoot}",
    "preLaunchTask": null,
    "runtimeExecutable": null,
    "runtimeArgs": [
      "--nolazy"
    ],
    "env": {
      "NODE_ENV": "development",
      "DEBUG": "gatsby:*"
    },
    "console": "integratedTerminal",
    "sourceMaps": true,
    "outFiles": []
   }
  ]
}

1 个答案:

答案 0 :(得分:1)

我能够通过使用全局安装的gatsby-cli的gatsby而不是node_modules中的那个来使它工作。所以:

npm install --global gatsby-cli

然后(因为我在nvm下使用node / npm等):

    {
        "type": "node",
        "request": "launch",
        "name": "Launch 'gatsby develop'",
        "protocol": "inspector",
        "program": "${env:HOME}/.nvm/versions/node/v8.11.3/bin/gatsby",
        "args": [
            "develop"
        ],
        "stopOnEntry": false,
        "cwd": "${workspaceRoot}",
        "preLaunchTask": null,
        "runtimeExecutable": null,
        "runtimeArgs": [
            "--nolazy"
        ],
        "env": {
            "NODE_ENV": "development",
            "DEBUG": "gatsby:*"
        },
        "console": "integratedTerminal",
        "sourceMaps": true,
        "outFiles": []
    }

为我工作。 不过我在OSX上,Windows设置可能需要更多更改。

另外:要在带有VSCode的nvm下使用节点,我在这里使用了默认的别名方法:Visual Studio Code to use node version specified by NVM