【发布时间】: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": [
"./**/*"
]
}
我将 include 从 src/**/* 更新为 ./**/*。
现在它编译 typescript 文件,但代码 2 仍然存在。
【问题讨论】:
-
请检查这是否有帮助。 stackoverflow.com/questions/44316064/…
-
如果您将代码示例与您键入的命令共享,以便其他人可以在本地运行它们,这将有所帮助。 @VarunJain 共享链接可能有答案。您的 Node.js 和 npm 版本不匹配可能是潜在原因之一。
标签: node.js typescript debugging visual-studio-code