React Native V63+报错:TurboModuleRegistry及LinkingManager不变违规
Hey there, I've run into both of these exact issues while working with React Native 0.63+ projects, so I can share some tried-and-true solutions that worked for me and other devs:
First: General Fixes for Invariant Violation: TurboModuleRegistry.getEnforcing(...)
This error usually pops up because React Native 0.63+ enables TurboModules (part of the New Architecture) by default, and either your native modules aren't registered properly or a dependency hasn't adapted to this change.
Disable TurboModules temporarily (quick fix if you're not ready for the New Architecture):
- For iOS: Update your
Podfilewith these settings, then runpod install:use_react_native!( :path => config[:reactNativePath], :fabric_enabled => false, :new_arch_enabled => false ) - For Android: Add this line to
android/gradle.properties:
Clean your project and rebuild afterward.newArchEnabled=false
- For iOS: Update your
Check third-party dependencies: If the error traces back to a specific library, check its docs to see if it supports TurboModules for RN 0.63+. If not, upgrade to the latest version, switch to an alternative library, or temporarily roll back to a compatible RN version.
Re-link native modules: Even though RN 0.60+ uses auto-linking, sometimes a manual link fixes glitches. Run:
npx react-native linkThen rebuild your project.
Second: Fixing Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'LinkingManager' not found
This specific error is tied to the Linking module, which got some changes in RN 0.63+. Here's how to fix it:
Verify your Linking import: Make sure you're using the official, up-to-date import instead of the old
LinkingManager:import { Linking } from 'react-native';LinkingManageris deprecated and has been rolled into the main Linking module.Reinstall react-native core: Corrupted core files can cause this issue. Run these commands:
npm uninstall react-native npm install react-native@your-current-rn-versionRebuild both iOS and Android projects after this.
Manual Link for iOS: If auto-linking failed, add the Linking module manually in Xcode:
- Open your project's
.xcworkspacefile - Right-click the
Librariesfolder and selectAdd Files to "[Your Project Name]" - Navigate to
node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeprojand add it - Go to
Build Phases > Link Binary With Librariesand addlibRCTLinking.a
- Open your project's
Check Android configuration: In
android/app/src/main/java/[your-package]/MainApplication.java, ensureLinkingPackageis included in your packages list:import com.facebook.react.modules.linking.LinkingPackage; @Override protected List<ReactPackage> getPackages() { List<ReactPackage> packages = new PackageList(this).getPackages(); // Add this if it's missing from the auto-generated list packages.add(new LinkingPackage()); return packages; }Clean the project and rebuild once done.
内容的提问来源于stack exchange,提问作者Rajesh N

