Leo
Leo

Reputation: 5142

How do I setup VSCode to run and debug KeystoneJS application

I am trying to setup VSCode to run and debug my KeystoneJS application.

I currently run the application using npm run dev or yarn dev - in package.json, the dev script is set like this:

  "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. I would love to understand why this is not working...

I tried to setup my debug configuration in launch.json like this:

    "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

error screenshot

Upvotes: 2

Views: 1460

Answers (1)

Gautam Singh
Gautam Singh

Reputation: 1138

this is how you can do this by changing npm script for 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.

You must do this after cross-env as indicated above and not like below.

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

Edit: 8 may You can use following config in launch.json in vscode, (ideally the npm script should be called debug)

With 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

Upvotes: 1

Related Questions