【问题标题】:Process exited with code 2 while debug in nodejs vscode在nodejs vscode中调试时进程以代码2退出
【发布时间】:2021-05-11 23:02:38
【问题描述】:

我有想要在 VSCode 中以调试模式运行的 nodejs 项目

这是项目结构

.vscode
  - launch.json
services
  - user
     - server.ts
package.json
tsconfig.json
tslint.json

这里是 package.json 脚本标签

"scripts": {
    "clean": "del-cli ./dist/*",
    "prestart": "yarn clean && tsc",
    "start": "yarn serve",
    "serve": "node dist/server.js",
    "start-dev": "yarn prestart && concurrently \"tsc --watch \" \"nodemon dist/server.js\""
},

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": "Launch Program",
            "cwd": "${workspaceFolder}",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "runtimeArgs": ["run-script","prestart"],
            "runtimeExecutable": "npm",
            
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ]
        }
    ]
}

这正在显示

C:\Program Files\nodejs\npm.cmd run-script prestart

> myproj@1.0.0 prestart C:\PERSONAL\projects\myproj
> yarn clean && tsc && yarn copyfiles

c:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:255

c:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:71
Process exited with code 2

更新 1

因为 tsconfig.json 中的路径无效而引发了问题

{
    "compilerOptions": {
        "baseUrl": "./",
        "target": "es2015",
        "module": "commonjs",
        "moduleResolution": "node",
        "removeComments": true,
        "sourceMap": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "pretty": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "outDir": "dist",
        "typeRoots": [
            "node_modules/@types"
        ]
    },
    "include": [
        "./**/*"
    ]
}

我将 includesrc/**/* 更新为 ./**/*

现在它编译 typescript 文件,但代码 2 仍然存在。

【问题讨论】:

  • 请检查这是否有帮助。 stackoverflow.com/questions/44316064/…
  • 如果您将代码示例与您键入的命令共享,以便其他人可以在本地运行它们,这将有所帮助。 @VarunJain 共享链接可能有答案。您的 Node.js 和 npm 版本不匹配可能是潜在原因之一。

标签: node.js typescript debugging visual-studio-code


【解决方案1】:

我找到了

An error code (also exit code) of 2 means "File not found"

就我而言,项目包含多个子项目。 package.json 中提到了依赖项,但它没有以某种方式安装,所以通过运行

npm install

命令,为我工作。

【讨论】:

    猜你喜欢
    • 2020-09-28
    • 2022-07-18
    • 2021-08-08
    • 1970-01-01
    • 2020-12-24
    • 2019-07-07
    • 2022-10-06
    • 1970-01-01
    • 2019-07-01
    相关资源
    最近更新 更多