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

180
Visualizações
How do I run a NodeJS script in typescript with create-react-app?

I have an app I created with create-react-app, using the following versions:

  • Node v16.15.1
  • Typescript v4.3.2
  • react-scripts v4.0.3 (though I am open to answers that require react-scripts v5)

I want to compile and run an executable NodeJS script written in Typescript using the same configuration as the React App. Additionally, I need to be able to import files from the rest of the app into my script.

e.g. /src/scripts/myscript.ts

import foo from '../util/foo'

const result = foo(process.argv[2])

console.log(result)

The closest I have gotten is:

npx ts-node --esm src/scripts/myscript.ts

However it only works if I add "type": "module" to my package.json, which breaks npm start. Even then, my script breaks on the export keyword.

I can create a package.json in the scripts folder with "type": "module" and a tsconfig that extends the app config:

{
  "extends": "../tsconfig.json",
  "include": ["**/*.ts"],
  "compilerOptions": {
    "noEmit": false,
    "outDir": "build"
  }
}

But this runs into issues with import/export in the imported typescript files.

If react-scripts has the correct config to compile and run Typescript files in its start and build scripts, how do I run a custom script?

about 4 years ago · Juan Pablo Isaza
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