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

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

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