I am new to using monorepo with Typescript which has a react-native project and a common folder which contains the common files to be shared across projects and it is configured and works fine when the app is running.
I am facing problem with Typescript which shows error in the common files import statements where react-native components are imported and used. It says Cannot find module 'react-native' or its corresponding type declarations.ts(2307). So is there a way to make Typescript to look for the import into the react-native project (Mobile directory) node_modules?
Monorepo structure:
monorepo
|
|---Common
|
|---Mobile
Common's tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": [
"es2021"
],
"moduleResolution": "node",
"noEmit": false,
"strict": true,
"target": "esnext",
"rootDir": "./",
"outDir": "./dist",
"composite": true,
"declaration": true,
"declarationMap": true,
"baseUrl": ".",
},
}
Mobile's tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"jsx": "react-native",
"lib": [
"es2021"
],
"moduleResolution": "node",
"noEmit": false,
"strict": true,
"target": "esnext",
"baseUrl": ".",
"paths": {
"*": ["*", "../Common/*"]
},
"composite": true,
"rootDir": "./",
"outDir": "./dist",
"declaration": true,
"declarationMap": true,
},
"references": [{ "path": "../Common" }],
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
]
}