0
votes

Violation invariante: requireNativeComponent: "RNCWebView" est introuvable dans UIManager

Bonjour les amis, j'ai eu cette erreur après avoir lié react-native-webview à mon projet

import React, { Component } from 'react';
import { WebView } from 'react-native-webview';

export default class App extends Component {
  render() {
    return (
      <WebView
        originWhitelist={['*']}
        source={{ html: '<h1>Hello world</h1>' }}
      />
    );
  }
}

Et il y a mon code

Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager.

    This error is located at:
        in RNCWebView (at WebView.android.js:250)
        in RCTView (at WebView.android.js:253)
        in WebView (at App.js:7)
        in App (at renderApplication.js:45)
        in RCTView (at AppContainer.js:109)
        in RCTView (at AppContainer.js:135)
        in AppContainer (at renderApplication.js:39)

Image d'erreur dans mon Android


1 commentaires

Pouvez-vous nous en dire plus sur le projet dans lequel vous souhaitez l'utiliser et son code? Avez-vous vérifié ce que disent les lignes dans les fichiers (c'est-à-dire dans WebView.android.js) mentionnées dans les erreurs? Vous pourriez nous donner ce code, c'est peut-être un début pour creuser. Merci.


5 Réponses :


3
votes

exécuter le react-native link react-native-webview

vérifier: https://github.com/react-native-community/react-native-webview/issues/140


0 commentaires

2
votes

J'ai eu le même problème. Essayez d'ajouter cette ligne à votre fichier pod: -

pod 'react-native-webview', :path => PROJECT_PATH + 'react-native-webview'

puis allez dans le dossier ios cd ios et installez pods pod install

Cela a résolu ce problème pour moi.


2 commentaires

J'ai exécuté le lien et je pense qu'il a automatiquement ajouté la ligne à mon fichier pod, que je n'avais qu'à installer le pod cd ios et que cela a finalement fonctionné 🙏


Oui ça marche



0
votes

100% garantie de la technique de travail

  1. supprimer le dossier pods et podfile.lock
  2. supprimer npm react-native-webview
  3. installer npm je réagis-native-webview
  4. cd ios
  5. installation du pod
  6. réaction native run-ios
  7. réinitialiser le cache

// c'est tout


2 commentaires

J'ai oublié le frère d'installation du pod


essayez les étapes ci-dessus, cela fonctionne sûrement



0
votes

J'ai fait les étapes ci-dessous:

"react": "16.9.0",
"react-native": "0.61.5"

Cela a installé la bibliothèque manquante, c'est -à-dire react-native-webview et ajouté ci-dessous la ligne au fichier Podfile.

 pod 'react-native-webview', :path => '../node_modules/react-native-webview'

environnement sur lequel je travaille:

 1. cd ios
 2. rm Podfile.lock
 3. pod install


0 commentaires

0
votes

ma solution à ce problème était la suivante:

Android

1 ajoutez ceci dans votre android / settings.gradle

...
  pod 'react-native-webview', :path => '../node_modules/react-native-webview'
...

2 ajoutez ceci dans votre android / app / build.gradle

import com.reactnativecommunity.webview.RNCWebViewPackage;//add this import
....

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNCWebViewPackage(),//add line
          ....

3 dans votre MainApplication.java:

dependencies {
    implementation project(':react-native-webview')
    ....

IOS

1 ajoutez la ligne suivante dans votre ios / Podfile puis ouvrez votre terminal, accédez au dossier ios de votre projet et exécutez l'installation du pod

include ':react-native-webview'
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android')


0 commentaires