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

259
Vistas
Import text file with ts-node

I'd like to import a text file:

import text from "./text.txt";

I have a file with:

declare module "*.txt" {
  const content: string;
  export default content;
}

However, ts-node complains with:

error TS2307: Cannot find module './text.txt' or its corresponding type declarations.

Please note that I cannot use the fs module to read the file since I am also using the same code for the web frontend (where the import is resolved by the bundler).

EDIT

Trying to use the proposal in the first answer:

import text from "./text.txt!text";

with

declare module "*!text" {
  const content: string;
  export default content;
}

I get this error:

Cannot find module './text.txt!text' from '...'
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

you have to tell typescript that your module will be a string type like that: import text from "./text.txt!text";

over 4 years ago · Santiago Trujillo 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