Skip to content

eds-tokens-sync: Figma sync broken after Vite 8 / Rolldown bump #4880

Description

@eddiman

Description

pnpm run update-tokens (and every per-file variant: update-tokens:foundations, update-tokens:color-static, update-tokens:color-dynamic, update-tokens:spacing-primitives, update-tokens:spacing-modes, plus the update-figma:* counterparts) fails on import before doing any Figma work, with:

Error: Calling `require` for "fs" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.
    at .../packages/eds-tokens-sync/dist/color-BXdZrUk8.js:11:8

Reproduces against a clean working tree on main.

Root cause

  1. PR chore(deps): bump vite from 7.3.2 to 8.0.3 #4759 bumped Vite 7 → 8. Vite 8 swaps Rollup for Rolldown as the bundler.
  2. PR chore(config): rename rollupOptions to rolldownOptions for Vite 8 #4762 renamed rollupOptionsrolldownOptions in packages/eds-tokens-sync/vite.config.ts. The config externalizes only fs and path.
  3. The script entrypoints do import 'dotenv/config'. Rolldown bundles dotenv into the output chunk. dotenv's source calls require(\"fs\"), require(\"path\"), require(\"os\").
  4. Rolldown emits a runtime helper that uses require() if it exists at runtime, otherwise throws. The package is \"type\": \"module\", so the bundle runs as pure ESM — require is not in scope. The helper throws on the first require(\"fs\") call.

Why this slipped through

update-tokens is rarely run — only when designers change Figma variables. No sync has been attempted on main since the Vite 8 bump on April 8.

Reproduction

cd packages/eds-tokens
pnpm run update-tokens:spacing-modes

(also fails for any other update-tokens:* / update-figma:* script)

Suggested fix

In packages/eds-tokens-sync/vite.config.ts, externalize Node built-ins and dotenv so they aren't bundled into the ESM output:

rolldownOptions: {
  external: [/^node:/, 'fs', 'path', 'os', 'dotenv', 'dotenv/config'],
},

Alternatively, inject createRequire via a banner so the runtime helper resolves correctly. Externalizing is the cleaner option since the consumers are Node CLI scripts.

Impact

  • Cannot pull token changes from Figma into the repo.
  • Cannot push token changes from the repo back into Figma.
  • Blocks 5xl letter spacing for UI typography is incorrect #4876 (5xl tracking-wide fix) — the upstream Figma fix exists, but the synced JSON cannot be regenerated until this is resolved.

Metadata

Metadata

Assignees

Labels

🐛 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions