简体   繁体   English

如何设置 VSCode 以运行和调试 KeystoneJS 应用程序

[英]How do I setup VSCode to run and debug KeystoneJS application

I am trying to setup VSCode to run and debug my KeystoneJS application.我正在尝试设置 VSCode 来运行和调试我的 KeystoneJS 应用程序。

I currently run the application using npm run dev or yarn dev - in package.json, the dev script is set like this:我目前使用npm run devyarn dev运行应用程序 - 在 package.json 中,开发脚本设置如下:

  "scripts": {
    "dev": "cross-env NODE_ENV=development DISABLE_LOGGING=true keystone dev"
  },

If I try to run cross-env NODE_ENV=development DISABLE_LOGGING=true keystone dev from my prompt, I get the error, command not found.如果我尝试从提示符运行cross-env NODE_ENV=development DISABLE_LOGGING=true keystone dev ,我会收到错误,找不到命令。 I would love to understand why this is not working...我很想了解为什么这不起作用...

I tried to setup my debug configuration in launch.json like this:我尝试在 launch.json 中设置我的调试配置,如下所示:

    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/keystone",
            "stopOnEntry": false,
            "args": [],
            "cwd": "${workspaceFolder}",
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "PORT":"3030",
                "NODE_ENV":"development",
                "DISABLE_LOGGING":"true" 
            }
        }
    ]
}

but it returns the error但它返回错误

错误截图

this is how you can do this by changing npm script for dev这就是您可以通过更改开发人员的dev脚本来做到这一点的方法

"dev": "cross-env PORT=4000 NODE_ENV=development NODE_OPTIONS=--inspect DISABLE_LOGGING=true keystone dev",

NODE_OPTIONS=--inspect or NODE_OPTIONS=--inspect-brk does the magic. NODE_OPTIONS=--inspectNODE_OPTIONS=--inspect-brk具有魔力。

You must do this after cross-env as indicated above and not like below.您必须在cross-env之后执行此操作,如上所示,而不是如下所示。

"dev": "NODE_OPTIONS=--inspect cross-env PORT=4000 NODE_ENV=development DISABLE_LOGGING=true keystone dev", (does not work) "dev": "NODE_OPTIONS=--inspect cross-env PORT=4000 NODE_ENV=development DISABLE_LOGGING=true keystone dev", (不起作用)

Edit: 8 may You can use following config in launch.json in vscode, (ideally the npm script should be called debug )编辑:5 月 8 日您可以在启动中使用以下配置。在launch.json中的 json,(理想情况下 npm 脚本应该称为debug

With NPM与 NPM

{
    // Use IntelliSense to learn about possible 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": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
          "run-script",
          "dev"
        ],
        "port": 9229,
        "skipFiles": [
          "<node_internals>/**"
        ]
      }
    ]
}

with YARN带纱

{
    // Use IntelliSense to learn about possible 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": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "yarn",
        "runtimeArgs": [
          "dev"
        ],
        "port": 9229,
        "skipFiles": [
          "<node_internals>/**"
        ]
      }
    ]
}

change port only if you change port in NODE_OPTIONS in package.json script仅当您在 package.json 脚本中更改 NODE_OPTIONS 中的端口时才更改端口

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM