0

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 :)

Addjoy
  • 1
  • 1
  • This should help https://stackoverflow.com/questions/44114436/the-create-react-app-imports-restriction-outside-of-src-directory – ishaba Aug 09 '21 at 13:50

1 Answers1

0

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.
Rohit Garg
  • 104
  • 5