wix / react-native-ui-lib

UI Components Library for React Native
https://wix.github.io/react-native-ui-lib/
MIT License
6.45k stars 706 forks source link

Throws error for unused optional peer dependencies #1560

Closed fruityperson closed 2 years ago

fruityperson commented 3 years ago

Describe the bug

Fresh install of RNUILib, Expo v4.0.15. When importing throws errors that an optional peer dependency is missing. Error can be fixed by manually installing that dependency even though it's not used.

Console output:

Unable to resolve module react-native-linear-gradient from /Users/xxx/Documents/yyy/zzz/node_modules/react-native-ui-lib/src/optionalDependencies/LinearGradientPackage.js: react-native-linear-gradient could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  2 |
  3 | try {
> 4 |   LinearGradientPackage = require('react-native-linear-gradient');
    |                                    ^
  5 | } catch (error) {}
  6 |
  7 | export default LinearGradientPackage;

Please notice the .../optionalDependencies/... in the path.

To Reproduce

Expected behavior

optional dependencies are not required unless they are used

Code snippet

(unrelated parts cut)

import React from "react";
import { View, Text, Card } from "react-native-ui-lib";
import { SafeAreaView, FlatList } from "react-native";

function Card(i) {
  // <Card>
  //   <View>
  //     <Text></Text>
  //   </View>
  // </Card>;
  return null;
}

function Screen() {
  const keyExtractor = (i) => String(i.id);

  const data = {items:[1,2]}

  return (
    <SafeAreaView>
      <FlatList data={data.items} renderItem={Card} />
    </SafeAreaView>
  );
}

export default Screen;

Screenshots

Device (please complete the following information)

Additional context

ethanshar commented 3 years ago

Can you check which version of metro you have installed? Run npm ls metro

fruityperson commented 3 years ago

Here's the output:

└─┬ react-native@0.63.2 invalid
  └─┬ @react-native-community/cli@4.14.0
    ├─┬ metro-config@0.59.0
    │ └── metro@0.59.0 deduped
    └── metro@0.59.0

I am sorry I don't fully understand the this. What I can say is I created the project with Expo CLI a couple of days ago so I don't know why it's invalid.

fruityperson commented 3 years ago

As a quick fix, can you please provide a list of all optional dependencies for this library as I don't seem to find then in the docs.

fruityperson commented 3 years ago

Update: i have found all optional dependencies and installed them, but the same bug started to appear with dependencies themselves

fruityperson commented 2 years ago

I figured out that the error is due to incompatibility with Expo. Version 5.21 works fine.

ethanshar commented 2 years ago

Please try our latest version (6.1.x) We fixed some issues related to Expo

Also I updated our setup guide and separated between our Peer dependencies (Which are mandatory at the moment) and our Optional dependencies