Skip to content

fix(storage): [C09] fix ESM circular init and wire system-test:esm - #9906

Draft
feywind wants to merge 1 commit into
c09/pubsub-emulator-ghafrom
c09/storage-esm-system-test
Draft

feywind wants to merge 1 commit into
c09/pubsub-emulator-ghafrom
c09/storage-esm-system-test

Conversation

@feywind

@feywind feywind commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes storage ESM initialization bugs and enables system-test:esm in Cloud Build.

Impact

Prevents Node 24 ESM crashes and adds ESM system test coverage.

Changes

  • Extract RequestError and FileExceptionMessages from handwritten/storage/src/file.ts into a zero-import leaf module handwritten/storage/src/file-errors.ts and re-export them from src/file.ts for full backwards compatibility.
  • Update src/resumable-upload.ts, src/hash-stream-validator.ts, and src/transfer-manager.ts to import RequestError and FileExceptionMessages from ./file-errors.js, and convert FileMetadata in src/resumable-upload.ts to import type, breaking the resumable-upload.js -> file.js -> storage.js -> file.js ESM Temporal Dead Zone cycle.
  • Add postcompile:esm in handwritten/storage/package.json to copy src/package-json-helper.cjs into build/esm/src so compile:esm works on a clean build/ directory.
  • Add a run-system-tests-esm step to handwritten/storage/cloudbuild.yaml to run pnpm run system-test:esm after run-system-tests.

Testing

  • Verified clean ESM compilation (rm -rf build && pnpm run compile:esm) copies package-json-helper.cjs into build/esm/src.
  • Verified build/esm/system-test --dry-run loads all 3 suites (install.js, kitchen.js, storage.js, 258 total tests) on both Node 24 (v24.15.0) and Node 22 (v22.16.0) without TDZ errors or dropped files.
  • Verified live ESM execution of build/esm/system-test/kitchen.js (should create an upload URI) on Node 24 against GCS: passed.
  • Ran pnpm --dir handwritten/storage test: 1,103 passing, 0 failing.
  • Ran bin/linter.mjs --strict and direct ESLint across all 5 touched .ts files: 0 errors, 0 warnings.
  • Ran core/test-utils breaking-change check: no breaking public TypeScript interface changes detected.

Alternatives

  • Wiring pnpm run system-test:esm into cloudbuild.yaml without fixing these two bugs fails on Node 24 (ReferenceError: Cannot access 'File' before initialization and ERR_MODULE_NOT_FOUND on clean builds).

@feywind
feywind added this pull request to stack #9907 November 18, 2026 22:47
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the codebase by extracting RequestError and FileExceptionMessages from file.ts into a new dedicated file file-errors.ts, updating all dependent files to import from this new location. Additionally, it updates the build scripts in package.json to separate the CJS and ESM post-compile steps, and adds a new step in cloudbuild.yaml to run ESM system tests using Node 24. There are no review comments to address.

@feywind

feywind commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

This is just preliminary test-run work on this one.

This branch has not been deployed

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

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant