Addjoy
Addjoy

Reputation: 1

running multiple react app and using common components from one folder

I created a common folder outside the multiple react apps and pasted the common jsx component in them. but when I tried to access those common components in each of the react apps, I started to get an error saying that I couldn't import files outside the src/ directory of a react project.

Project Structure
Main Compomnent(folder)
React-app-1
React-app-2
React-app-3
React-app-4

I tried various paths and require, and react-app-rewire but couldn't get it to work. I even tried some ways from this site but no luck.

I tried to import the components as a dependency as well but it didn't work out.

so can any of you guys can help me out with this? Appreciate the help :)

Upvotes: 0

Views: 1326

Answers (1)

Rohit Garg
Rohit Garg

Reputation: 114

You can not access files that are not in the src folder.

You should create a separate repo for the common component. To access those components there are multiple ways -

  1. You can clone that repo somewhere fixed path in every project and import with the path
  2. Create common components as a different package with its own dependencies and use them with a symlink or with Lerna
  3. you can publish the npm as private and add it in package.json.

Upvotes: 1

Related Questions