island: ESM entry with top-level await fails via sync call path (ERR_REQUIRE_ASYNC_MODULE)

Open
#3,415 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Domain
backend, devtools

Research direction

Start by tracing the island call path through packages/runtime/src/scr_node_island_host.cjs, especially load(path, esm) and the createRequire/Module._load path described in the issue. Reproduce with the Ink example and inspect how ESM entries with top-level await reach callSync. Done when the reproduction loads without ERR_REQUIRE_ASYNC_MODULE through the appropriate async island call path.

Written by the indexing model from the issue text.

Description

Summary

An island package whose module graph contains top-level await fails to load: the island's call path require()s the ESM entry, and Node throws ERR_REQUIRE_ASYNC_MODULE inside the embedded libnode — the error propagates out of callSync.

This is where ink stops on main (all its former SC9001 build ICEs are fixed — it now compiles fully, with react/es-toolkit/react-reconciler correctly routed to islands).

Reproduction

import { render, Text } from "ink";
render(React.createElement(Text, null, "hello"));

Builds ✅, then at runtime:

Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await
Required module: ~/.cache/scriptc/node-islands/<hash>/node_modules/ink/build/index.js
    at ModuleLoader.importSyncForRequire

packages/runtime/src/scr_node_island_host.cjs load(path, esm) does have an import() branch for esm modules — but the call path that reaches ink's entry apparently goes through createRequire/Module._load instead. A fix likely needs esm entries routed through import() (and therefore an async island call) when the module graph has TLA.

Verified on main (d4c82a5c3), darwin-arm64, libnode pack per packages/libnode-common/build-pack.mjs.

Dominant language
TypeScript
Stars
6.7k
Forks
229
Avg merge
14h 29m
Merged PRs (30d)
787

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel-labs/scriptc

All issues in vercel-labs/scriptc

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.