8

I am learning typescript with visual studio code in Windows 10 and I am getting an error to run simple program.
"Cannot launch program 'E:\typescriptBasis\main.ts' because corresponding JavaScript cannot be found." hence I am not able to debug code.

I have installed nodejs version v10.2.1
I have installed npm version v5.6.0
I have installed typescript globally v2.8.3
I have installed Visual sudio code v1.23.1

launch.json file

  "version": "0.2.0",   
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "sourceMaps": true,
            "name": "Launch Program",
            "program": "${workspaceFolder}/main.ts",
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ]
        }
    ]
}

tsconfig.json file

{  
  "compilerOptions": {   
    "target": "es5",                     
    "module": "commonjs",                    
    "sourceMap": true   
    }   
}

tasks.json

{   
    "version": "2.0.0",   
    "tasks": [   
        {    
            "type": "typescript",   
            "tsconfig": ".vscode\\tsconfig.json",   
            "option": "watch",   
            "problemMatcher": [   
                "$tsc-watch"   
            ]   
        },   
        {   
            "type": "typescript",   
            "tsconfig": ".vscode\\tsconfig.json",   
            "problemMatcher": [   
                "$tsc"   
            ],   
            "group": {   
                "kind": "build",   
                "isDefault": true   
            }   
        }    
    ]   
}   

main.ts file

console.log("this is my first program of typescript");

6
  • You have to run tsc in the terminal to generate a .js file Commented May 28, 2018 at 7:57
  • Yes, I did that also >>tsc main.ts and js file also generated. but still, I have the same issue... Commented May 28, 2018 at 12:26
  • how are you trying to run the .js file? in node ? node main.js or in a browser? <script src='main.js'> Commented May 28, 2018 at 13:35
  • I am just running the application in Visual Studio code. there is run an icon. after click on that, I am getting an error. Commented Jun 1, 2018 at 12:52
  • 2
    I think the run icon is for debugging? You still need to compile your .ts file to a .js file, for example by typing tsc in the terminal or pressing cmd+shift+b Commented Jun 1, 2018 at 16:01

1 Answer 1

3

I have it working with the following launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "preLaunchTask": "TSC",
            "program": "${file}",
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ]
        }
    ]
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",        
    "module": "commonjs",      
    "allowJs": false,          
    "sourceMap": true,         
    "strict": true,            
    "noUnusedLocals": true,    
    "noUnusedParameters": true,
    "noImplicitReturns": true, 
    "esModuleInterop": true    
  }
}

and tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "TSC",
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        }
    ]
}

And my current version of VS Code is 1.28.2

Sign up to request clarification or add additional context in comments.

1 Comment

Version 1.41.1 works well, but it has something weird. If I include my explicit typescript, it doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.