我有一个 nodejs 项目,我想在 VSCode 中以调试模式运行
这是项目结构
.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": [
"./**/*"
]
}
我将 include 从 src/**/*
更新为 ./**/*
。
现在它编译了打字稿文件,但仍然存在代码 2。
答案 0 :(得分:0)
我找到了
An error code (also exit code) of 2 means "File not found"
就我而言,项目包含多个子项目。 package.json 中提到了依赖关系,但它没有以某种方式安装,所以通过运行
npm install
命令,对我有用。