23

Hello friends i got this error after linking react-native-webview to my project

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)

And there is my code

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>' }}
      />
    );
  }
}

Error Image in my android

Sky Sakthi
  • 402
  • 1
  • 4
  • 12
  • Can you tell us some more about the project you want to use it in and its code? Have you checked what the lines in the files (i.e. in WebView.android.js) mentioned in the errors are saying? You could give us this code, maybe it is a start to dig in. Thank you. – rank May 16 '20 at 12:17

13 Answers13

17

run react-native link react-native-webview

check: https://github.com/react-native-community/react-native-webview/issues/140

user13142973
  • 625
  • 1
  • 6
  • 11
  • 4
    This is not needed anymore if you are using React Native 0.60+, simply `cd ios` and `pod install`, maybe restart xCode, possibly in Xcode click in the menu on Product > Clean Build Folder, and you should be good to go – Raphael Pinel Jan 28 '21 at 09:17
13

With React Native 0.60+, no need to add anything to the podfile. Try again cd ios && pod install

If it doesn't help, try restarting the simulator and rebuilding the app. Restarting Xcode is also a good idea.

You could optionally clean the build Folder in XCode enter image description here

Raphael Pinel
  • 2,352
  • 24
  • 26
5

Try these steps.

  1. Delete pods folder and podfile.lock
  2. npm uninstall react-native-webview
  3. npm i react-native-webview
  4. cd ios
  5. pod install
  6. (npx) react-native run-ios
  7. Reset cache
tripleee
  • 175,061
  • 34
  • 275
  • 318
Ruban Dharmaraj
  • 985
  • 1
  • 8
  • 11
4

I had the same issue. Try Add this line to your podfile :-

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

then go to ios folder cd ios and install pods pod install

It has resolved this problem for me.

Akshita Agarwal
  • 235
  • 3
  • 4
4

Make sure you did:

  1. npx pod-install
  2. npx react-native run-ios

After installing the package you. need to update pods and then run the project again.

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116
2

my solution for this problem was the following:

Android

1 add this in your android/settings.gradle

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

2 add this in your android/app/build.gradle

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

3 in your MainApplication.java:

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
          ....

IOS

1 add the following line in your ios/Podfile and then open your terminal, go to your project ios folder and run pod install

...
  pod 'react-native-webview', :path => '../node_modules/react-native-webview'
...
Dey
  • 842
  • 9
  • 21
1

I had the same issue before , I tried this:

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

SLDem
  • 2,065
  • 1
  • 8
  • 28
1

I update webView to the latest (11.18.1) and it was fixed without any additional linking steps.

0

I have done below steps:

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

This installed the missing library i.e. react-native-webview and added below line to Podfile file.

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

environment which I am working on:

"react": "16.9.0",
"react-native": "0.61.5"
Dharman
  • 30,962
  • 25
  • 85
  • 135
amit pandya
  • 1,384
  • 13
  • 22
0

Follow these simple steps worked for me:

  1. Rebuild the App. Run:
npx react-native run-android
  1. Run:
react-native link react-native-webview
  1. Check if RNCWebViewPackage is imported in MainApplication.java file, which looks something like this:
import com.reactnativecommunity.webview.RNCWebViewPackage;

Note: I'm using react-native@0.64.2.

kartik tyagi
  • 6,256
  • 2
  • 14
  • 31
0

There is no need to add anything or use the link for React Native 0.60+. In my case, which was android, I simply build the project again using: $ npm run android

Gilad M
  • 942
  • 10
  • 12
0

Have you tried to link manually?

Go to ../node_modules/react-native-webview/ios and drag and drop the RNCWebView.xcodeproj to Libraries folder on Xcode, right after, Go to Build Phases tab (on Xcode) in the section "Link binary With libraries" add the libRNCWebView.a (inside Libraries/RNCWebView.xcodeproj/Products). Try to build and run

-1

try to re-build your project after installation and link of webview package (npx react-native run-android)