diff --git a/docs/bundler/loaders.mdx b/docs/bundler/loaders.mdx index 41b57350d7ac..4a77af6af6ef 100644 --- a/docs/bundler/loaders.mdx +++ b/docs/bundler/loaders.mdx @@ -148,6 +148,11 @@ var config = { config.logLevel; ``` + + Bun compiles TOML date/time values to `Temporal.*.from()` calls, for every `target`. The runtime that loads the bundle + needs a `Temporal` global. See [Date and time values in bundles](/runtime/toml#date-and-time-values-in-bundles). + + If you pass a `.toml` file as an entrypoint, Bun converts it to a `.js` module that `export default`s the parsed object. diff --git a/docs/runtime/toml.mdx b/docs/runtime/toml.mdx index 5139ef473b7e..490b8f74eb04 100644 --- a/docs/runtime/toml.mdx +++ b/docs/runtime/toml.mdx @@ -287,6 +287,28 @@ This means: - Smaller bundle sizes - Tree shaking of unused properties (named imports) +### Date and time values in bundles + +Bun compiles each TOML date/time value to a call on the `Temporal` global. The call runs when the bundle loads, for every `target`: + +```toml config.toml +name = "my-app" +released = 2026-08-15 +``` + +```js Output +var config_default = { + name: "my-app", + released: /* @__PURE__ */ Temporal.PlainDate.from("2026-08-15"), +}; +``` + +A runtime without `Temporal` throws `ReferenceError: Temporal is not defined` when it loads the bundle. Bun has `Temporal`. Node.js 24 and earlier do not. To run the bundle on a runtime without `Temporal`, do one of the following: + +- Import only the keys you use (`import { name } from "./config.toml"`). Bun tree-shakes the unused keys, including the date/time values. +- Quote the value in the TOML file (`released = "2026-08-15"`) so Bun emits a string. +- Import a module that defines `globalThis.Temporal`, such as a Temporal polyfill, before the TOML file. Bun keeps the import order, so the polyfill runs before the date/time calls. + ### Dynamic Imports You can also dynamically import TOML files: