简体   繁体   中英

Sharing components between two react projects in same repo

I have two projects in the same repo that I'd like to be able to share components. Ideally, under the root folder, I'd like to have a separate folder for my first project, containing all node modules, ios files, etc, and a separate similar folder for my second project. Then I'd like to create a 'shared' folder on the same level, containing only the components I am sharing between the two. So ideally, all three of those folders will be at the same level, under the root folder. When trying to import a component from the 'shared' folder within my project, it first told me it needed a package.json. After I created that, it gives me the error "unable to resolve [folderName] as a folder: it contained a package, but its 'main' could not be resolved".

Has anyone had any experience with this? If I want my two projects to be able to access components within the shared folder, how should I go about structuring the folders?

react-native look for package.json only if you import from a folder .

import from a file instead.

example:

import { Button } from './shared/button/mybuttonjs';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM