npm-installed library not working

I ran this from the command line to add a library to my Expo app:

yarn add react-native-text-size
react-native link react-native-text-size

Then rebuilt my app. However, when I import and use in a component with:

import rnTextSize from 'react-native-text-size';
...
componentDidMount() {
 const size = rnTextSize.measure({
    text: 'Measure me baby'
 });
}

It throws this error:

TypeError: TypeError: undefined is not an object (evaluating '_reactNativeTextSize.default.measure')

Is there an Expo-related reason why a third-party npm library can’t be used? Or am I missing something about getting a third party library to show up in NativeModules?

https://docs.expo.io/versions/latest/introduction/faq/#how-do-i-add-custom-native-code

Have you ejected?

1 Like

No, and that will be why. I was looking at this documentation:

https://docs.expo.io/versions/latest/react-native/native-modules-setup/

But it didn’t mention that you need to eject. I’ll get on that.

Thanks very much.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.