Starting TypeScript program from Visual Studio Code: "Cannot launch program 'hw.ts' because correspondi

I have hw.ts file with this content:function greeter(x: string) {return "Hello" + x;}let u =

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 pile file from the mandline:

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 pile & run TypeScript program from VSCode? What am I missing?

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

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 pile file from the mandline:

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 pile & run TypeScript program from VSCode? What am I missing?

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

Share Improve this question asked Feb 15, 2018 at 19:30 LetMeSOThat4ULetMeSOThat4U 6,82810 gold badges58 silver badges102 bronze badges 1
  • Follow this official guide: code.visualstudio./docs/typescript/typescript-tutorial – Rayee Roded Commented Aug 20, 2019 at 17:33
Add a ment  | 

4 Answers 4

Reset to default 3

It worked for me as soon as I changed

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

to

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

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 piled *.js files to the corresponding *.ts files.
Example:

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

In your launch.json file replace

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

for

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

It worked for me.

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 mand 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745411926a4626572.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信