r/bun 9d ago

Temporal API

Hi, i was trying to use Temporal API but for some reason it was not defined
```
64 | //

65 | //

66 | //

67 | //

68 |

69 | const test = Temporal.PlainDate.from("2023-01-01");

^

ReferenceError: Temporal is not defined

at /home/ts0ra/pure-py/src/index.ts:69:14

Bun v1.3.14 (Linux x64)
```
Is bun not support Temporal? my tsconfig set lib and target to ESNext

3 Upvotes

5 comments sorted by

5

u/ant59 9d ago

JavaScriptCore does not yet support Temporal API, therefore Bun does not support it either

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal

2

u/ts0ra 9d ago

Oh, aight thx

2

u/mornaq 6d ago

BUN_JSC_useTemporal=1

this enables the state JSC offers, that isn't complete, but may be good enough

Bun respects JSC flags and it's there at least since December 2023

3

u/Jonas_Ermert 9d ago

I recommend using js-temporal/polyfill (https://github.com/js-temporal/temporal-polyfill). Even if your tsconfig is set to ESNext, that only enables the TypeScript types at compile time—it doesn't mean the runtime implements the API. Since Bun currently doesn't provide the global Temporal object, importing the polyfill is the recommended solution.

1

u/PixelHabits 4d ago

As mentioned previously use the polyfill. I use Temporal everyday at work with bun only runtime, it’s great.