Skip to content

Schedule's eager Cron import makes effect/Effect's module graph require Intl/ICU, which breaks static (AOT) compilation #10900

Done

Description

@espetro

Summary

effect/Effect cannot be statically (AOT) compiled by scriptc on targets whose runtime has no ICU data, because effect/Schedule statically imports effect/Cron, which reaches new Intl.DateTimeFormat through internal/dateTime.

The offending chain is:

effect/Effect
  -> internal/schedule        (packages/effect/src/Effect.ts imports internal/schedule)
  -> Schedule                 (packages/effect/src/internal/schedule.ts:6)
  -> Cron                     (packages/effect/src/Schedule.ts:15  `import * as Cron from "./Cron.ts"`)
  -> internal/dateTime        (packages/effect/src/Cron.ts:19     `import * as dateTime from "./internal/dateTime.js"`)
  -> new Intl.DateTimeFormat  (packages/effect/src/internal/dateTime.ts:338, :367)

Because internal/schedule.ts imports Schedule.ts as a static namespace import, every program that imports effect/Effect pulls Cron into its module graph, whether or not it ever uses a schedule.

Exact error

Building the smallest possible program against effect 4.1.5 with scriptc 0.4.16:

// t2.ts
import { runSync, succeed } from "effect/Effect"
console.log(runSync(succeed(42)))
$ scriptc build t2.ts --npm-static effect -o bin2
/private/tmp/eff-unpatched/t2.ts:1:1 - error SC3002: the macos-arm64 runtime pack has no ICU objects, which Intl needs; reinstall a runtime package that supports Intl

  1 | import { runSync, succeed } from "effect/Effect"
    | ^

1 error.

Nothing about the program uses dates, cron or time zones. Deleting the single line import * as Cron from "./Cron.js"; from dist/Schedule.js (and nothing else) makes the exact same program compile and print 42. So that one import edge is the whole blocker.

Minimal reproduction (3 modules, no effect needed)

cron.ts

const mk = () => new Intl.DateTimeFormat("en-US", { timeZone: "UTC" })
export const next = () => mk().format(new Date())

schedule.ts

import * as Cron from "./cron.ts"
export const cron = () => Cron.next()

main.ts

import { cron } from "./schedule.ts"
console.log(typeof cron)

scriptc build main.ts -o out succeeds here, because scriptc tree-shakes at function granularity and next is never called from the program's reachable set. Changing the last line to console.log(cron()) fails with:

error SC3002: the macos-arm64 runtime pack has no ICU objects, which Intl needs; reinstall a runtime package that supports Intl

A lazy import() does not help

We tried making the edge lazy, as the obvious fix:

// schedule.ts
export const cron = async () => (await import("./cron.ts")).next()

The compiler follows the literal dynamic import into the module graph, so the Intl-using function is still compiled and the build still fails with SC3002. Confirmed with the same 3-module repro (dynamic import + a call into the imported module). The only thing that works is removing the Cron import edge from the graph entirely.

Tree-shaking granularity is why this is fixable

Scriptc prunes at function granularity across modules: in the repro, an Intl use inside a function that is never reachable from an imported export does not trigger SC3002, while the same use reached through an imported function does. The problem is therefore the static import edge from Schedule.ts to Cron.ts, which keeps Cron's exports alive as potential entry points. A fix has to break that edge, not merely make the call lazy.

Proposed options, in order of preference

  1. Move Schedule.cron (and the Cron module) behind a separate entry point. Export the cron functionality from its own module (for example effect/Cron), and have effect/Schedule no longer import it. A consumer that never uses cron then has no Intl edge at all, while Schedule.cron keeps working for those who import the cron entry point explicitly. This is the option we would most like to see, because it keeps the current API shape for cron users and removes the edge for everyone else.

  2. Make Cron.ts not depend on Intl. As far as we can tell, the cron parsing and next/prev computation do not inherently need Intl.DateTimeFormat; only the human-readable time-zone handling in internal/dateTime.ts (zoneMakeNamedUnsafe, zoneMakeLocal) does, and those are reached from Cron via dateTime.makeZonedUnsafe when a named time zone is used. If the cron engine computed wall-clock fields itself (or if dateTime had an Intl-free path for offset arithmetic), the whole effect/Effect graph would be free of Intl. This is a bigger change than option 1 but removes the dependency at the source.

Note also that Cron reaches Intl only through internal/dateTime, so option 2 is really "make internal/dateTime's named-zone path not require Intl".

Impact

This blocks static/AOT compilation of the entire effect/Effect module for any consumer whose runtime lacks ICU data. The downstream project (https://github.com/espetro/coordinate) works around it with a local pnpm patch that removes the Cron import from dist/Schedule.js and stubs Schedule.cron to throw; we would much rather depend on an upstream fix than on a patch that disables a public API.

Happy to send a PR for either option if that is the direction you prefer. For reference, the measurements above were taken with scriptc 0.4.16 on macOS arm64 against effect 4.1.5.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions