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

178
Vistas
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 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