1 of 9

Import Text

TC39 2025-11

2 of 9

In a similar manner to why importing JSON or raw bytes is useful in JavaScript, importing text is useful, and should be just as easy.

Problem Statement

3 of 9

Possible Solutions

Fetch API

let response = await fetch("path/to/file.txt");

let text = await response.text();

Import Bytes (currently at Stage 2.7)

import uint8array from "path/to/file.txt" with { type: "bytes" };

let text = new TextDecoder().decode(uint8array);

Import Text

import text from "path/to/file.txt" with { type: "text" };

3

4 of 9

Fetch API Limitations

The operations are always async.

The fetch starts only when the the JavaScript is being executed.

Relative paths are rooted at the document's base URL rather than that of the module from which it's being fetched.

4

01

02

03

5 of 9

Preferred Solution

import text from "path/to/file.txt" with { type: "text" };

5

6 of 9

Importing Text with a JS-Specified Encoding

Requires importing it as an Uint8Array, and explicitly decoding it:

import uint8array from "path/to/file.txt" with { type: "bytes" };

let text = new TextDecoder("utf-16le").decode(uint8array);

6

7 of 9

Stage 1?

����

7

8 of 9

Stage 2?

�Proposed spec text: eemeli.org/proposal-import-text

8

9 of 9

Stage 2.7?

�Proposed spec text: eemeli.org/proposal-import-text

�Draft test262 PR: tc39/test262#4607

(pending reviewer approvals)

9