Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
How can I compile TypeScript within a JavaScript app?

I have a build.js file which, as you may have guessed, builds my project. This file aims to:

  • Compile .ts files and place them into a new directory.
  • Create an asar containing the compiled files.

Because typescript (tsc) is an NPM package, I figured I might be able to use it inside of a JavaScript file, in the same way I can use the asar package. I was right; I can use the typescript package as a regular Node.JS module, however, I do not know how to use it, and ESLint doesn't help me out too much.

Here's my current build.js:

const typescript = require("typescript");

I cannot find any documentation for this, all I want to do is replicate what tsc . would do.

EDIT: I do not want to use child_process, because it creates new issues, especially when it comes to cross-compatibility and safety.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use child process to spawn a shell and run the tsc command or use the exec() to spawn the shell first then run the command

https://www.geeksforgeeks.org/node-js-child-process/

You can achieve this with something like

const { exec } = require('child_process');
exec('tsc', (error, stdout, stderr) => {
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }
console.log(stdout);
  if (stderr!= "")
  console.error(`stderr: ${stderr}`);
});

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!