alx*_*nkt 7 debugging visual-studio-code strapi
我正在尝试在 VS Code 中调试我的 Strapi 项目(3.0.0 beta 16.6)。我的launch.json:
{
"type": "node",
"request": "attach",
"name": "Attach to strapi",
"port": 9229
}
Run Code Online (Sandbox Code Playgroud)
我的 package.json:
"scripts": {
"debug": "node --inspect=127.0.0.1:9229 ./node_modules/strapi/bin/strapi.js develop"
}
Run Code Online (Sandbox Code Playgroud)
调试器附加到进程,但我所有的断点都变得未经验证(显示为黑色,而不是红色)。我的配置有什么问题?
小智 10
在属性中添加VS配置“NODE:通过npm启动”.vscode/launch.json
"configurations"
并运行
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"develop"
],
"port": 9229,
"skipFiles": [
"<node_internals>/**"
],
"console": "integratedTerminal"
}
Run Code Online (Sandbox Code Playgroud)
这个答案来自以下Strapi/strapi 问题:
我想出了下一个解决方案:在 server.js 文件中包含下一个脚本(我的自定义脚本):
const strapi = require('strapi');
strapi({ dir: process.cwd(), autoReload: true }).start();
Run Code Online (Sandbox Code Playgroud)
我正在通过下一个命令使用 nodemon: nodemon --inspect=0.0.0.0:9228 server.js
现在我可以9228
通过调试器附加到。
只是为了添加到@alxnkt 评论。我遇到了同样的问题并通过将launch.json更改为端口9230来解决它
{
"type": "node",
"request": "attach",
"name": "Attach to strapi",
"port": 9230
}
Run Code Online (Sandbox Code Playgroud)
同时将 package.json 上的端口保持为 9229
"debug": "node --inspect=127.0.0.1:9229 ./node_modules/strapi/bin/strapi.js develop"
Run Code Online (Sandbox Code Playgroud)
在调用 Strapi develop 命令(可能是管理面板及其核心服务器)时,不知何故有 2 个进程在运行,我们必须监视的进程变成了端口 9230。
这对我使用 Strapi v4 有用
{
"version": "0.2.0",
"configurations": [
{
"name": "STRAPI Debug",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "node",
"runtimeVersion":"14.19.0",
"runtimeArgs": ["--lazy"],
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceRoot}/node_modules/@strapi/strapi/bin/strapi.js",
"args": [
"develop"
],
"protocol": "inspector",
"env": {
"NODE_ENV": "development"
},
"autoAttachChildProcesses": true,
"console": "integratedTerminal"
},
]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4159 次 |
最近记录: |