react-native-vector-icons: RNVectorIconsManager not available, did you add library to your project and link with libRnVectorIcons.a

using "react-native": "0.42.0" & "react-native-vector-icons": "^4.0.0", & Xcode 8.2.1

still getting this error after install and running react-native link . Is the process not automatic?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (6 by maintainers)

Most upvoted comments

I am getting the same issue, but only when running component tests with Jest - Is there an example mock for testing purposes?

@chrismllr or to anyone reaching here because you are testing with jest and testing the getImageSource, you can mock that function like this (point to any icon):

import {
    NativeModules,
  } from 'react-native';

NativeModules.RNVectorIconsManager = {
    getImageForFont: function getImageForFont(fontFamily, glyph, fontSize, color, callback) {
        return callback(null, require('../app/resources/icons/icon.png'));
    }
}

I got rid of the cocoapods. It just isn’t easy to upgrade this repo consistently with it, but it may be more about react-native link integration than anything.

I just came across this issue because I needed to mock getImageSource. A slightly-different syntax from what @sfratini posted above worked for me:

import { NativeModules } from 'react-native'

jest.mock('NativeModules', () => {
  return {
    RNVectorIconsManager: {
      getImageSource: function getImageSource(fontFamily, glyph, fontSize, color, callback) {
        return callback(null, require('../app/resources/icons/icon.png'));
      }
    },
  };
});

The trick was understanding that we’re not mocking react-native-vector-icons here, we’re mocking the underlying NativeModule.

I’m going to close this, please open a PR with proposed documentation changes if you think they are still unclear.

@systemlevel: the link phase you’re showing is not for your project, click on s2h_mobile and ensure you’re linking there.

It is frustrating, @oblador, but I do believe it is more RN than this repo. I think you’ve done a great job providing a seriously quality library. If you read above, I noted using cocoapods with this lib makes for very flaky uprades and specifically said “it may be more about react-native link integration than anything.”

So I am not dismissing this lib by any stretch. It is worth noting other libraries I use do not have the same problems as this one. There are some that do, though; hence the above quote.