Skip to content

Chrome 155 lets you import text files as JS strings

The with { type: "text" } import attribute, a Stage 3 TC39 proposal already supported in Deno and Bun, ships in Chrome's stable channel from 6 October.

Chrome 155, released to the stable channel on 6 October, adds text import attributes: import text from "./file.txt" with { type: "text" }; loads a plain text file and binds it as a string, with no fetch call or bundler loader required.

The feature implements the TC39 “Import Text” proposal, which has reached Stage 3 under champion Eemeli Aro. It extends the same import-attributes mechanism already used for with { type: "json" } JSON modules to raw text. Deno and Bun already support the syntax; Chrome is the first browser to ship it.

import prompt from './prompt.txt' with { type: 'text' };

Why it matters: anywhere you currently fetch a prompt template, a CSV fixture, a shader or any other plain-text file and await the response body, you can now import it directly as a module and let the browser handle the loading. It’s one more case where a small project can skip a bundler loader plugin entirely.

The caveat: this is Stage 3, not yet finalised in ECMA-262, and Firefox and Safari haven’t shipped support. Code that has to run across browsers still needs a fetch fallback for now.

Share

Related reading

More from The Wire

All briefs