在nodejs vscode中调试时以代码2退出进程



我有一个nodejs项目,我想在VSCode中以调试模式运行

下面是Project结构

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

,这是包裹。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 Filesnodejsnpm.cmd run-script prestart
> myproj@1.0.0 prestart C:PERSONALprojectsmyproj
> yarn clean && tsc && yarn copyfiles
c:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecycleindex.js:255
c:Program Filesnodejsnode_modulesnpmlibutilserror-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": [
"./**/*"
]
}

我更新了包括src/**/*./**/*

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

我发现

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

在我的例子中,项目包含多个子项目。依赖项在package中有提及。Json文件,但是没有安装,所以运行

npm install

命令,为我工作。

相关内容

最新更新