Importing text files

Text files can be imported in JS and TS files using the import keyword. This makes including static data in a library much easier. Stable .8: no flag required. (Binary bytes imports are still experimental and require --unstable-raw-imports.)

Edit on GitHub

./main.ts

Text files can be imported in JS and TS modules. When doing so, you need to specify the `type: "text"` import attribute.

import text1 from "./log.txt" with { type: "text" };

console.log(text1);

Dynamic imports are also supported.

const text2 = (await import("./log.txt", {
  with: { type: "text" }
})).default;

console.log(text2);

./log.txt

2025-07-01 08:15:12 - Program started
2025-07-01 08:16:45 - Uploading file: summary.xls
2025-07-01 08:17:33 - Error: Invalid file format (xls)
2025-07-01 08:18:01 - Uploading file failed: summary.xls

Run this example locally using the Ende CLI:

ende run https://docs.ende.sh/examples/scripts/importing_text.ts

Additional resources