I am trying to set up a monorepo as I thought sharing common code is a great idea in an ecosystem of applications as they have a lot of common types, logic and functions. My repo includes a React Native app, a React app, a Next app, and an Express backend application as well.
I am using Yarn workspaces. And I have added shared-types
as a dependency in the React Native and React apps. The auto imports work fine in the React app but not in the React Native. When I manually add the import everything works fine, but the auto imports just wouldn't work.
I have done some digging but couldn't find anything useful. The things that I've looked up include this question about sharing common code and this question that uses paths
to solve it. Nothing has worked so far for me.
root package.json
"workspaces": [
"apps/*",
"backend/*",
"packages/*"
]
The folder structure is as follows.
|
|__ apps
| |__react-native-app
| |__react-app
| |__next-app
|__ backend
| |__express-app
|__ packages
|__ shared-types
After a week of constant scratching of the head, I found the solution to this problem by looking at the default tsconfig.json
created by tsc --init
.
All I needed to do was add the following flags and it started working. The updated tsconfig.json
looks like this
{
"declaration": true,
"declarationMap": true
}