0

I have nodejs project that I want to run in debug mode in VSCode

Here is the Project structure

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

and here is the package.json scripts tag

"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\""
},

and the 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"
            ]
        }
    ]
}

and this is showing

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

Update 1

it was raising issue because invalid path in 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": [
        "./**/*"
    ]
}

I updated include from src/**/* to ./**/*.

Now it compiling the typescript files but still exist with code 2.

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
  • 1
    Please check is this helps. https://stackoverflow.com/questions/44316064/gyp-err-build-error-stack-error-make-failed-with-exit-code-2 – Varun Jain Feb 08 '21 at 13:36
  • It would help if you share the an example of code with the commands you typed so that others can run them in their local. @VarunJain shared link might have the answer. Probably your Node.js and npm version mismatch would be one of the potential reason. – Anit Shrestha Feb 09 '21 at 09:24

1 Answers1

0

I found

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

In my case, project contains multiple sub projects. The dependency is mentioned in package.json but it was not installed somehow, so by running

npm install

command, worked for me.

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189