Skip to content

fix(native): report resolver disagreement only under diagnostics - #204

Open
danfry1 wants to merge 2 commits into
mainfrom
fix/issue-201-resolver-agreement-diagnostics
Open

danfry1 wants to merge 2 commits into
mainfrom
fix/issue-201-resolver-agreement-diagnostics

Conversation

@danfry1

@danfry1 danfry1 commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Fixes #201. Thanks to @doutatsu for the report, and for tracing it to checkResolverAgreement — the analysis was right.

Problem

Every test file printed 'test-renderer' resolves to two different files, along with the same warning for nanoid and Babel's source-map packages. Nothing in those projects loads those packages through Vite: Node requires test-renderer from React Native Testing Library and nanoid from postcss.

The check runs on every Node require and compares the resolved file against the first Vite main field in the package manifest. It has no view of Vite's module graph, so a package only Node ever requires is indistinguishable from one both graphs load. Its suggested remedy didn't help either, because it compares against a fixed field list rather than the project's resolve.mainFields.

Change

  • The check now runs under diagnostics only. The silent duplicate-instance failure it was written to surface — a store written through one copy reading back unset through the other — is still worth reporting to someone debugging it.
  • The message states that it reports a risk rather than a proven duplicate, and that the comparison uses Vite's default main fields.

Verification

  • tests/resolver-agreement-gate.test.ts drives the installed require hook in a subprocess, rather than calling the checker directly, because the gate is at the call site. It asserts silence by default and the warning under diagnostics, and fails without the change.
  • In a project matching the report (RN 0.86.3, Vitest 5.0.0, pnpm with node-linker=hoisted, RNTL 14), the warnings are gone by default and still appear with diagnostics: true.
  • prepublishOnly passes, plus format:check.

The check compares Node's resolution against the package manifest and
never sees Vite's module graph, so a package only Node requires looks
exactly like one both graphs load. It fired on every test file for
test-renderer (required by React Native Testing Library), nanoid
(required by postcss) and Babel's source-map packages, none of which
Vite loads.

It now runs under diagnostics, where the silent duplicate-instance
failure it was written to surface is still worth reporting. The message
says it is a risk rather than a proven duplicate, and that its
comparison uses Vite's default main fields.

Fixes #201
Node's ESM loader rejects a bare Windows path ('D:\…') as an unsupported
URL scheme, so the subprocess that drives the require hook failed on the
Windows leg of the gate.
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.

Native engine: 'resolves to two different files' fires for packages that only Node loads

1 participant