7

I have hw.ts file with this content:

function greeter(x: string) {
    return "Hello" + x;
}

let u = "John";
document.body.innerHTML = greeter(u);

I select Start without debugging and VSCode says:

Cannot launch program 'hw.ts' because corresponding JavaScript cannot be found.

OK so I compile file from the commandline:

tsc hw.ts

Now I do have hw.js in the same folder.

So again I select Start without debugging and VSCode again says Cannot launch program 'hw.ts' because corresponding JavaScript cannot be found..

Is there any way to compile & run TypeScript program from VSCode? What am I missing?

(I do have node in my PATH, it should be visible to VSCode)

1

4 Answers 4

3

It worked for me as soon as I changed

  "outFiles": [
    "./dist/**/*.js"
  ],

to

  "outFiles": [
    "${workspaceFolder}/dist/**/*.js"
  ],
Sign up to request clarification or add additional context in comments.

Comments

0

Be sure that you have set the correct path to your *.js files in the launch.json. This can be done by defining the outFiles option. Furthermore, to enable debugging *.ts files you can set sourceMaps to true. This tells vscode that it should try to map the compiled *.js files to the corresponding *.ts files.
Example:

"sourceMaps": true,
"outFiles": [
    "${workspaceFolder}/path/to/your/jsFiles/**/*.js"
] 

Comments

0

In your launch.json file replace

"outFiles": ["${workspaceFolder}/**/*.js"]

for

"outFiles": ["${fileDirname}/**/*.js"]

It worked for me.

Comments

-1

I had the same issue. I solved it using the following steps:

1.Configure

Specify output directory and enable sourceMap in tsconfig.json

"outDir": "./out",  /* Specify .js output files. */
"sourceMap": true   /* Generate corresponding .map files. */

2.Build

Now Click Run Build Task (Shift + Command(Ctrl) + B) from the Terminal menu of the VS Code and type the following command and press enter:

tsc: watch - tsconfig.json

You need to Run Build Task once when you first open the project. This will start watching for code changes in the project.

3.Run

Now go to the Typescript program that you want to run (Make sure your program file .ts has the focus).

From the Run menu, click Run Without Debugging(Ctrl + F5).

You can see the output in the Debug Console.

Comments

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.