IssueRaiser

Including local packages from outside project root. Can we do better?

### Introduction My goal is to find a solution to include packages which reside outside of the directory tree of a project. By "project," I refer to a React Native directory that contains a `package.json` and `node_modules` generated using `npx react-native init <name>`. Consider the application and package directories as follows: ``` /home/sam/apps/my-app /home/sam/development/my-package ``` In this setup, `my-app` represents my React Native project, while `my-package` is my private UI component library. The objective is to incorporate `my-package` into `my-app`. `my-package` contains a `package.json` and some source files, typically located in the `src` directory. --- ### Why? The ability to store a package in a single location and share it across multiple projects offers a clean and efficient way to manage code. It eliminates the need to synchronize every project that utilizes the package. ### Solution and the problem A common approach to achieve this is through the use of a monorepos. However, this may not always be the most preferred solution. Curently, it appears taht employing a monorepo is the only viable option for sharing local packages between React Native projects. Another potential solution involves leveraging the `nodeModulesPaths` and/or `extraNodeModules` features of `metro.config.js`. However, these features only function partially, and I'm in the process of investigating why and hopefully devising a fix. Consider the scenario where I have my o

Posted by samsnori on Feb 16, 2024, 10:44 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments

ux (SaaS)

Including local packages from outside project root. Can we do better?

samsnoriFeb 16, 2024, 10:44 PM

### Introduction My goal is to find a solution to include packages which reside outside of the directory tree of a project. By "project," I refer to a React Native directory that contains a `package.json` and `node_modules` generated using `npx react-native init <name>`. Consider the application and package directories as follows: ``` /home/sam/apps/my-app /home/sam/development/my-package ``` In this setup, `my-app` represents my React Native project, while `my-package` is my private UI component library. The objective is to incorporate `my-package` into `my-app`. `my-package` contains a `package.json` and some source files, typically located in the `src` directory. --- ### Why? The ability to store a package in a single location and share it across multiple projects offers a clean and efficient way to manage code. It eliminates the need to synchronize every project that utilizes the package. ### Solution and the problem A common approach to achieve this is through the use of a monorepos. However, this may not always be the most preferred solution. Curently, it appears taht employing a monorepo is the only viable option for sharing local packages between React Native projects. Another potential solution involves leveraging the `nodeModulesPaths` and/or `extraNodeModules` features of `metro.config.js`. However, these features only function partially, and I'm in the process of investigating why and hopefully devising a fix. Consider the scenario where I have my o

Comments (0)

No comments yet. Start the discussion.

Comment on this issue