Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda