admin管理员组文章数量:1426219
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)
- Follow this official guide: code.visualstudio./docs/typescript/typescript-tutorial – Rayee Roded Commented Aug 20, 2019 at 17:33
4 Answers
Reset to default 3It 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.
本文标签:
版权声明:本文标题:Starting TypeScript program from Visual Studio Code: "Cannot launch program 'hw.ts' because correspondi 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745411925a2657508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论