Resolver: Read `exports` from the package root, not the closest `package.json`
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, react-native
- Área
- build-system
Línea de trabajo
Start in packages/metro-resolver/src/resolve.js around the line where the package is looked up once (about L420), and trace how resolveFromNodeModulesPath, extraNodeModules and Haste pass the package root down. The change adds an opt-in resolver.unstable_resolveExportsFromPackageRoot flag that reads "exports" via getPackageForModule(packageRoot) when the subpath is empty. Done means the flag gates the new behaviour, existing tests pass with it off, and new tests cover nested package.json with root exports.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Metro reads "exports" from the package.json closest to the requested subpath, not the one at the package root. So a nested {"type": "commonjs"} or a legacy shim package.json hides the root's "exports", which is different to Node's PACKAGE_RESOLVE, webpack and Vite. Previously reported in #1517 and #1582, this is to track the fix.
Examples I've seen in real apps (AI-driven comparison): @floating-ui/utils/dom on Bluesky web gets the legacy shim's build instead of dist/floating-ui.utils.dom.mjs, and on Mattermost, ESM imports of rxjs/operators get dist/cjs while rxjs gets dist/esm5. @kitten and @Nezz have seen the same thing break swr.
The fix should be small now that #2134 looks the package up once, here:
Metro converts specifiers to absolute candidate paths early, so the caller has to pass the package root down. resolveFromNodeModulesPath has parsedSpecifier.packageName, extraNodeModules has the mapped directory and Haste has the directory of its package.json.
- For
"exports", usegetPackageForModule(packageRoot). It gives a realrootPath, so pnpm symlinks work, andpackageRelativePathcomes from the specifier's subpath. - If
packageRelativePathisn't empty, there's nopackage.jsonat the root, so keep using the closest to the target. "browser"redirections,"imports"and self-references all keep using the closestpackage.json, which is correct for those.
This should go behind resolver.unstable_resolveExportsFromPackageRoot, off by default, so that we can get it out in 0.87.x without changing what anyone resolves, and then enable it by default for 0.88.
It's breaking because some packages only work on native through a nested "browser" field that this bypasses. As @Om-singhaI found, @mswjs/interceptors/fetch goes from its browser build to its Node build, which needs node:zlib. nanoid/async (nanoid 3) also moves, and needs unstable_applyBrowserSpecAfterExports on as well to avoid importing crypto. Subpaths with a nested package.json that aren't in the root's "exports" will now warn, then fall back as they do today.
- Lenguaje dominante
- JavaScript
- Estrellas
- 5.7k
- Forks
- 711
- Merge medio
- 3 d 14 h
- PR fusionados (30 d)
- 77
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de react/metro
-
[metro-file-map] An error a watcher backend reports ends the server, since nothing listens for itPosiblemente ocupada @sorinc03 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
metro-file-map gives up on a fallback watcher that is still starting after a fixed 240 s, and leaves it runningPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
-
Published declarations import types from connect, @babel/core and @babel/traverse, whose @types packages are not dependenciesPosiblemente ocupada @sorinc03 la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de react/metro
Issues similares
-
clientV2: Application Info header separators show as missing-character boxes without a CJK fontAbiertobug new-client
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
NUWCDIVNPT/stig-manager#2285 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Fei2411/DeepSeek-Bot#922 · 1 reacción ·
-
server errored
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
OpenTermsArchive/contrib-declarations#4273 ·
Los mantenedores suelen responder en 1 día
-
needs-area-label
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 2 días
-
serienstream.toAbiertoN: AdGuard for Windows P2: High T: Annoyance
Dificultad 2/5 1-3 horas Aptitud para principiantes 61/100
AdguardTeam/AdguardFilters#246310 ·
Los mantenedores suelen responder en 1 día