NodeJS VSCode launch.json调试子文件夹中的节点项目

zdwk9cvp  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(163)

我在主项目中有一个节点项目作为子文件夹。我正在尝试为VS Code创建启动配置,以便在打开父文件夹时开始调试index.ts文件。下面是我的文件夹结构:

所以我的node项目在名为NodeBackend的子文件夹中。我想按下VS Code上的F5或绿色按钮,开始调试我的typescript文件。
当我在父文件夹中执行此操作时,我会得到一个错误:

Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

字符串
然而,当我在VS代码中加载“NodeBackend”项目并按F5或绿色按钮时,我可以毫无问题地调试它。
My launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceFolder}\\NodeBackend",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\NodeBackend\\src\\index.ts",
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ]
        }
    ]
}


下面是我的源代码:https://github.com/Kayes-Islam/SimpleProject

bnlyeluc

bnlyeluc1#

下面是我的launch.json,用于类似的项目结构:

{
    // 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": "Debug Express",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "cwd": "${workspaceFolder}\\backend",
            "program": "${workspaceFolder}\\backend\\src\\app.ts",
            "runtimeArgs": [
                "-r",
                "ts-node/register",
                "-r",
                "tsconfig-paths/register"
            ],
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ],
        }
    ]
}

字符串
上述配置工作,尽管控制台显示以下错误:

C:\Program Files\nodejs\node.exe -r ts-node/register -r tsconfig-paths/register .\src\app.ts
Could not read source map for file:///C:/Users/path/to/project/backend/node_modules/typescript/lib/typescript.js: ENOENT: no such file or directory, open 'c:\Users\path\to\project\backend\node_modules\typescript\lib\typescript.js.map'
(node:23068) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)


希望能帮上忙。干杯,

相关问题