Skip to content

Compile what an optional peer a package loads depends on - #976

Draft
danfry1 wants to merge 4 commits into
mainfrom
975-expo-transitive
Draft

danfry1 wants to merge 4 commits into
mainfrom
975-expo-transitive

Conversation

@danfry1

@danfry1 danfry1 commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

A package reached only as an optional peer has its dependencies compiled again. A dependency Node cannot link fails with UNDECLARED_DEPENDENCY_UNCOMPILED when compiling it would fix the link. A genuinely missing export stays Node's own error.

Why

Since 0.16.0 (#924), the dependency walk never followed an optional peer. Take a workspace library that lists expo as an optional peer and imports it. expo was compiled, but its dependencies were not. Node then ran expo-modules-core's ES module build as published, and every test file failed with "The requested module './EventEmitter' does not provide an export named 'EventEmitter'".

Changes

  • ecosystem.ts (loadedPeers): a workspace member's own optional React Native peer is followed without reading its imports. Workspace source is TypeScript of any shape, so an import the scan misses would be this bug again.
  • An installed package's peer is followed when the package's runtime files import it, optional or not. Following every optional peer compiled Expo's web peers (Ownership: an undeclared installed package's dependencies aren't compiled, and its optional peers are walked #883). A required peer that is detected is followed as before.
  • The import scan maps ./x.js, .mjs and .cjs imports to their TypeScript sources.
  • A reached workspace library that is not itself detected now has its peers followed too. Before, only its dependencies were.
  • explain.mjs: Node's link error ("does not provide an export named") is attributed to a recorded uncompiled dependency only when that dependency, or a recorded dependency it links, has a file of the requested name that exports the name.
  • Tests: tests/optional-peer-edge.test.ts covers CommonJS, NodeNext ./x.js, an unbuilt dist/, undetected libraries and an installed non-Expo library. tests/scan-found-dependency.test.ts covers platform-file, cross-package and genuinely missing exports. The bug museum gains exhibit res-optional-peer-workspace (a TypeScript workspace library), recorded as guard proven against a833f71.

How to review

Start at loadedPeers in ecosystem.ts and its two call sites, the walk and the reached-member seed. Then read linkedExportSource in explain.mjs.

Notes

  • The test "follows an installed optional peer the package loads" in ecosystem-closure.test.ts reverses an assertion from fix(native): compile a required React Native peer a compiled package loads, though nothing declares it #519, because that peer is installed and imported.
  • The detected set is identical on four Expo apps (158, 407, 333 and 534 packages). Detection on the largest takes about 1.5 ms longer (61.2 → 62.6 ms median). The run is recorded in the planning repository's perf-evidence/runs/20261204-runtime975-detection-sets.

Every edge rule in the walk, checked for dropping an edge because of how a dependency is declared rather than whether it is installed and loaded:

Rule Verdict
An optional peer is never followed (#924) Fixed
The import scan misses TypeScript ./x.js imports Fixed
A reached workspace member seeds only from dependencies Fixed: its peers too
optionalDependencies are not followed Kept. Following them added only platform binaries on four Expo apps, nothing React Native
A required peer that is not React Native is not followed Kept: by content, tested
The undeclared-import edge covers workspace members only Kept: an installed package's undeclared import cannot resolve under isolated installs
The toolchain and held closures read dependencies only Kept: they exclude, so following more would drop edges
A project's own peerDependencies are neither candidates nor seeds Gap, not this regression; a follow-up

Closes #975

…annot link

Since #924 an optional peer was never an edge of the dependency walk, so a workspace
library listing expo as an optional peer and importing it left expo's dependencies
uncompiled, and Node failed to link them. A peer is now followed when the package loads
it, optional or not, from a reached workspace library too. A link error in an uncompiled
dependency of an undeclared package fails with UNDECLARED_DEPENDENCY_UNCOMPILED.
It fails as its bug on a833f71 and passes before it and on the fix.
Workspace source is TypeScript of any shape, so a peer edge that needs the scan
to find the import misses NodeNext './x.js' imports and a main naming an unbuilt
dist/. The scan now maps .js imports to TypeScript sources for installed
packages. A link error is attributed to an uncompiled dependency only when a
file of the requested name in it exports the name.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.16.0: Expo fails to load when it is reached only as an optional peer

1 participant