我正试图设置VSCode来运行和调试我的KeystoneJS应用程序。
我目前使用 npm run dev
或 yarn dev
- 在package.json中,开发脚本是这样设置的。
"scripts": {
"dev": "cross-env NODE_ENV=development DISABLE_LOGGING=true keystone dev"
},
如果我尝试运行 cross-env NODE_ENV=development DISABLE_LOGGING=true keystone dev
在我的提示符中,我得到错误信息,命令未找到。我很想知道为什么这不能工作......
我试着在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"
}
}
]
}
但它返回的错误是
这就是你如何通过改变npm脚本来实现的。dev
"dev": "cross-env PORT=4000 NODE_ENV=development NODE_OPTIONS=--inspect DISABLE_LOGGING=true keystone dev",
NODE_OPTIONS=--inspect
或 NODE_OPTIONS=--inspect-brk
做的神奇。
你必须在 cross-env
如上所示,而不是像下面这样。
"dev": "NODE_OPTIONS=--inspect cross-env PORT=4000 NODE_ENV=development DISABLE_LOGGING=true keystone dev",
(不起作用)
编辑: 8 may您可以在以下配置中使用。launch.json
在vscode中,(理想情况下,npm脚本应该被称为 debug
)
有国家预防机制
{
// 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>/**"
]
}
]
}
与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>/**"
]
}
]
}
只有当您在package.json脚本中的NODE_OPTIONS中更改了端口,才会更改端口。