Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda