@react-native/[email protected] assigns module.exports inside an ES module, so non-Metro web bundles crash
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 74/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- javascript, react-native, webpack
Piste de recherche
L’issue identifie @react-native/assets-registry/registry.js comme le fichier en échec et indique les exports nommés de remplacement. Lis ce fichier et vérifie les déclarations de son package ; exécute ensuite un bundle web avec webpack 5 ou Rspack qui importe react-native-svg et utilise react-native-web comme alias de react-native. Le travail est terminé lorsque le bundle se charge sans l’erreur de module ES et que les imports nommés sont résolus.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
@react-native/[email protected] registry.js contains an import and then assigns module.exports. Rspack and webpack 5 treat a file with import as an ES module and throw when it assigns module.exports. The web bundle never evaluates past that file.
react-native-svg imports the named export, so any web bundle that includes it hits this on startup:
import { getAssetByID } from "@react-native/assets-registry/registry";
Metro accepts the mix, so native builds and Metro web builds do not throw.
This is not #48349. That issue was Flow syntax (export type) in the 0.76 file, fixed by #48458, which moved the types into comments and kept module.exports. The 0.88 file is a later rewrite: it imports AssetRegistry from react-native and still assigns module.exports. The published registry.d.ts already declares registerAsset and getAssetByID as named exports.
Published registry.js:
"use strict";
import { AssetRegistry } from "react-native";
/*::
export type {AssetDestPathResolver, PackagerAsset} from 'react-native';
*/
// eslint-disable-next-line @react-native/monorepo/no-commonjs-exports
module.exports = {
registerAsset: AssetRegistry.registerAsset,
getAssetByID: AssetRegistry.getAssetByID,
};
Replacing the assignment with named exports matches the .d.ts and lets the bundle load:
export const registerAsset = AssetRegistry.registerAsset;
export const getAssetByID = AssetRegistry.getAssetByID;
Steps to reproduce
- Install
[email protected],react-native-web, and[email protected]. - Bundle a web entry that imports
react-native-svgwith Rspack or webpack 5, aliasingreact-nativetoreact-native-web. - Load the bundle in a browser.
React Native Version
0.88.1
Affected Platforms
Runtime - Web
Output of npx @react-native-community/cli info
Not a stock React Native app. The failure is in the published @react-native/[email protected] package, loaded through [email protected] by an Rspack web build. react-native is 0.88.1 and react-native-web is 0.21.4.
Stacktrace or Logs
Uncaught (in promise) Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: .../node_modules/@react-native/assets-registry/registry.js
Rspack also reports, before the throw:
ESModulesLinkingWarning: export 'getAssetByID' (imported as 'getAssetByID') was not found in '@react-native/assets-registry/registry' (module has no exports)
from react-native-svg/lib/module/lib/resolveAssetUri.js.
Reproducer
The three accepted reproducer forms all bundle with Metro, and Metro does not throw on this file:
- A pull request that edits
RNTesterPlayground.jsruns inside RNTester, which uses Metro. - An Expo Snack uses Metro.
- The reproducer template is a Community CLI app, which also uses Metro.
The crash happens only when Rspack or webpack 5 bundles @react-native/assets-registry/registry.js. A project that reproduces it is a small web build that installs [email protected], react-native-web, and [email protected], aliases react-native to react-native-web, and bundles an entry that imports react-native-svg. Loading that bundle throws ES Modules may not assign module.exports from registry.js.
There is no public repository for that build yet.
- Langage dominant
- C++
- Étoiles
- 127k
- Forks
- 25.5k
- Merge moyen
- 3 j 22 h
- PR mergées (30 j)
- 258
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de react/react-native
-
Needs: Triage :mag:
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
react/react-native#60000 ·
Les mainteneurs répondent en général sous 2 jours
-
`yarn test-ios` exits before building RNTester: `objc-test.sh` launches the WebSocket server script #59433 deletedPeut-être pris @lazerg l’a pris il y a 5 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
react/react-native#59939 ·
Les mainteneurs répondent en général sous 2 jours
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primaryPeut-être pris @alleneubank l’a pris il y a 7 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
react/react-native#59919 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
react/react-native#59722 ·
Les mainteneurs répondent en général sous 2 jours
-
Android: new WebSocket() crashes the app for a URL that OkHttp or java.net.URI rejectsPeut-être pris @sorinc03 l’a pris il y a 15 jours. Ouverte🌐Networking Needs: Author Feedback Needs: Repro Platform: Android
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
react/react-native#59704 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de react/react-native
Issues similaires
-
ai_p2
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
ClickHouse/ClickHouse#132519 ·
Les mainteneurs répondent en général sous 1 jour
-
patch_advisor_json_integration fails when the build tree is reached through a symbolic linkPeut-être pris @DerKarussellbremser l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
boykopovar/AnyPS5#22581 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
[Bug]: VST3 getMidiControllerAssignment reads past midiControllerToParameter for program changeOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
juce-framework/JUCE#1810 ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
petercorke/robotics-toolbox-python#952 ·
Les mainteneurs répondent en général sous 1 jour