Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!