debugging 在Visual Studio程式码中两柴strapi

mxg2im7a  于 2022-12-13  发布在  其他
关注(0)|答案(8)|浏览(194)

我正在尝试调试我的strapi项目(3.0.0 beta 16.6)在VS代码。我的launch.json:

{
  "type": "node",
  "request": "attach",
  "name": "Attach to strapi",
  "port": 9229
}

我的包参:

"scripts": {
    "debug": "node --inspect=127.0.0.1:9229 ./node_modules/strapi/bin/strapi.js develop"
}

调试器连接到进程,但我的所有断点都未验证(显示为黑色,而不是红色)。我的配置有什么问题?

gblwokeq

gblwokeq1#

这个答案来自下面的Strapi/Strapi问题:
我想出了下一个方案:在server.js文件中有下一个脚本(我的自定义脚本):

const strapi = require('strapi');
strapi({ dir: process.cwd(), autoReload: true }).start();

我使用nodemon的下一个命令:nodemon --inspect=0.0.0.0:9228 server.js
现在我可以通过调试器连接到9228

yzuktlbb

yzuktlbb2#

只是添加到@alxnkt注解。我遇到过同样的问题,通过将launch.json更改为端口9230解决了它

{
  "type": "node",
  "request": "attach",
  "name": "Attach to strapi",
  "port": 9230
}

同时将package.json上的端口保留为9229

"debug": "node --inspect=127.0.0.1:9229 ./node_modules/strapi/bin/strapi.js develop"

在调用Strapi开发命令时,不知何故有2个进程正在运行(可能是管理面板及其核心服务器),我们必须监视的进程变成了端口9230。

doinxwow

doinxwow3#

添加VS配置“节点:通过npm启动”并运行

{
      "type": "node",
      "request": "launch",
      "name": "Launch via NPM",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run-script",
        "develop"
      ],
      "port": 9229,
      "skipFiles": [
        "<node_internals>/**"
      ],
      "console": "integratedTerminal"
    }
qojgxg4l

qojgxg4l4#

这对我使用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"
     },
    ]
}
l3zydbqr

l3zydbqr5#

通过将端口号设置为9203解决了此问题:

{
  "type": "node",
  "request": "attach",
  "name": "Attach to strapi",
  "port": 9229
}

但是我不知道它是如何工作的...

r7knjye2

r7knjye26#

我刚刚通过NPM启动了它,这是我的launch.json(在.vscode文件夹中)

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch via NPM",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run-script",
        "develop"
      ],
      "port": 9229,
      "skipFiles": [
        "<node_internals>/**"
      ],
      "console": "integratedTerminal"
    }
  ]
}
p5cysglq

p5cysglq7#

您也可以使用NODE_OPTIONS

NODE_OPTIONS='--inspect' yarn strapi develop

您将获得:

$ NODE_OPTIONS="--inspect" yarn strapi develop
Debugger listening on ws://127.0.0.1:9229/8564942a-6476-443a-9f64-87fa6d0055b7
For help, see: https://nodejs.org/en/docs/inspector
yarn run v1.22.5
$ strapi develop
Starting inspector on 127.0.0.1:9229 failed: address already in use
Debugger listening on ws://127.0.0.1:9230/7da840dd-cb89-493f-8ce0-e11530efdfbb
For help, see: https://nodejs.org/en/docs/inspector

现在您可以使用 *Debug:连接到节点进程 * 连接到端口9230。

h7appiyu

h7appiyu8#

对于strapi v4,您必须将"sourceMap": true添加到tsconfig.json文件的compilerOptions中。

相关问题