If a workspace uses a different library version than the one installed in the root /node_modules, that different library version must be installed in the workspace /apps//node_modules directory. #3 - Disable resolving dependencies using the hierarchical lookup strategy.#2 - Resolve dependencies in the order of the local /apps//node_modules and root /node_modules directories.In the Modify the Metro config step, we instructed Metro to do a couple of this, specifically: Open our app's package.json, change the main property to index.js, and create this new index.js file in the app directory with the content below. If you are using a managed project, we have to change our default entrypoint to node_modules/expo/AppEntry.js. In monorepos, we can't hardcode paths to packages anymore since we can't be sure if they are installed in the root node_modules or the workspace node_modules folder. Whenever a library imports react, or any other library, Metro always resolves the library from the nodeModulesPaths we defined.Īs long as the apps/mobile/node_modules path has the correct library version and is listed as the first nodeModulesPaths entry, we should always get the correct version of that library. When we disable this hierarchical lookup, it should not matter where the React Native library is installed. This option is documented in the Metro Resolution Algorithm documentation, under step 5. node_modules - The root folder, contains and apps/mobile/node_modules - The app's folder, contains hierarchical lookup enabled, whenever expo imports react, Metro will resolve to and not This causes "multiple React versions" errors in your app.īy disabling hierarchical lookup, we can force Metro to resolve only folders from the nodeModulesPaths = order we defined in #2.As a result, monorepo tooling, like Yarn, will install these dependencies to the root node_modules directory, for example: node_modules - The root folder, contains apps/mobile/node_modules - The app's folder, contains modules and React Native libraries usually don't add react as a peer dependency.(uses monorepo tooling like Yarn, React is installed in two different node_modules folders. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |