You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document: under the ownership models a dual package's import loads its require build #838
area:ownershipWhich side (Node or Vite) loads a module; double instances, aliases, mocks reaching Node codedocumentationImprovements or additions to documentationpriority:mediumReal friction with a workaround
Under experimental.ownershipModel ('resolver' or 'resolution'), an ES import of a package resolves through the require export condition. Metro resolves it through import.
import * as Badge from "pkg" in a test file loads build/index.js under both ownership models, with or without the hot runtime. Without the flag it loads build/index.mjs. Metro 0.87 picks the condition per dependency (metro-resolvermatchSubpathFromExportsLike: context.isESMImport === true ? "import" : "require"), so an app bundle gets build/index.mjs.
A package whose ES and CommonJS builds differ therefore runs a different build under the ownership models than in the app. The fixture tests-native/fixtures/rn-esbuild-reexport-lib shows it: import.meta.resolve("rn-esbuild-reexport-lib") from a test under tests-native/vitest.ownership.config.mts gives build/index.js.
Expected: an ES import resolves through import, and a require through require, as Metro decides it.
Decision: keep the one-instance rule. This becomes a documented known difference, not a resolver change.
The ownership models give every package one owner and one file, so a test's import and a library's require of the same package return the same object. packages/vitest-native/docs/ownership-model.md ("require wins") records this as the intended trade-off, and src/native/shared-resolver.mjs implements it: one condition set, the CommonJS one Node applies in the workers.
Matching Metro per request would bring back the case the models exist to remove. Metro picks import or require for each dependency, so an app that reaches a dual package both ways bundles both builds, and module-level state (React contexts, registries, instanceof checks) splits between them. In a test, that shows up as a context reading its default value or a second registry. That is worse than running the CommonJS build of a package whose two builds are normally the same source compiled twice.
Narrower rules considered and not taken:
The owner's realm picks the condition (import for packages Vite owns, require for packages Node owns). This keeps one file, but a require of a Vite-owned dual package would then get the ES build's namespace instead of module.exports, which Metro never gives a require. It trades one difference from Metro for another.
import for everything. This relies on require(esm) for every Node-owned package, and React Native packages and their Jest support expect CommonJS semantics there.
Per-request conditions with a dedupe check. Two files cannot be one module instance, so this goes back to the dual-instance case.
Follow-up:
Document it as a known difference: in the guide's package entry points section (website/guide/how-it-works.md) and in the fidelity matrix. Say that under the ownership models a package with separate import and require builds runs its require build in tests, that an app bundle may use the import build, and that resolve.alias pins a specific file where the two builds behave differently.
Revisit if a real package turns up whose ES and CommonJS builds behave differently in a way a test can observe. That evidence would justify a per-package opt-in rather than a change to the default.
This issue is now a documentation item. The docs change will close it.
changed the title [-]Ownership models resolve an ES import through the require condition, unlike Metro[/-][+]Document: under the ownership models a dual package's import loads its require build[/+]on Nov 14, 2026
This stays docs-only. Under the ownership models, require wins for a dual package, and only one instance loads; that is a deliberate design choice. The change is to document it: the "Package entry points" section of website/guide/how-it-works.md, and a row in the fidelity matrix, should say that an ES import of a dual package loads its require build under the ownership models, unlike Metro.
area:ownershipWhich side (Node or Vite) loads a module; double instances, aliases, mocks reaching Node codedocumentationImprovements or additions to documentationpriority:mediumReal friction with a workaround
Activity
test: the ES-index pin holds without an ownership model; the models r…
danfry1 commentedon Nov 14, 2026
Decision: keep the one-instance rule. This becomes a documented known difference, not a resolver change.
The ownership models give every package one owner and one file, so a test's
importand a library'srequireof the same package return the same object.packages/vitest-native/docs/ownership-model.md("requirewins") records this as the intended trade-off, andsrc/native/shared-resolver.mjsimplements it: one condition set, the CommonJS one Node applies in the workers.Matching Metro per request would bring back the case the models exist to remove. Metro picks
importorrequirefor each dependency, so an app that reaches a dual package both ways bundles both builds, and module-level state (React contexts, registries,instanceofchecks) splits between them. In a test, that shows up as a context reading its default value or a second registry. That is worse than running the CommonJS build of a package whose two builds are normally the same source compiled twice.Narrower rules considered and not taken:
importfor packages Vite owns,requirefor packages Node owns). This keeps one file, but arequireof a Vite-owned dual package would then get the ES build's namespace instead ofmodule.exports, which Metro never gives arequire. It trades one difference from Metro for another.importfor everything. This relies onrequire(esm)for every Node-owned package, and React Native packages and their Jest support expect CommonJS semantics there.Follow-up:
website/guide/how-it-works.md) and in the fidelity matrix. Say that under the ownership models a package with separateimportandrequirebuilds runs itsrequirebuild in tests, that an app bundle may use theimportbuild, and thatresolve.aliaspins a specific file where the two builds behave differently.This issue is now a documentation item. The docs change will close it.
[-]Ownership models resolve an ES import through the require condition, unlike Metro[/-][+]Document: under the ownership models a dual package's import loads its require build[/+]fix(native): an imported namespace carries the names a module re-expo…
danfry1 commentedon Nov 15, 2026
This stays docs-only. Under the ownership models,
requirewins for a dual package, and only one instance loads; that is a deliberate design choice. The change is to document it: the "Package entry points" section ofwebsite/guide/how-it-works.md, and a row in the fidelity matrix, should say that an ESimportof a dual package loads itsrequirebuild under the ownership models, unlike Metro.