I am struggling with few issues related to package managements in my project using yarn workspaces.
So, I have a React Native mobile app (1st package) using a "lowcode engine" (2nd package) that generates screens based on JSON config and using a set of UI components from a design system package combining React Native Web and storybook stuff (3rd package).
The lowcode / JSON config is prepared in a React.js web admin app (4th package) by including 3rd and 4th packages for preview. Finally I need to share some types/interfaces/classes between 2nd and 3rd package, so I created a package in "@types/engine" (5th package). All the packages are exclusively TS and uses vite (except the mobile app => metro)
Here's my root package.json file :
{
"name": "monorepo",
"private": true,
"packageManager": "[email protected]",
"workspaces": [
"./@types/*",
"Mobile",
"Engine",
"Admin",
"DesignSystems/*"
],
"devDependencies": {
"@types/node": "^22.9.0",
"eslint": "^8.57.1",
"prettier": "^3.3.3",
"ts-node": "^10.9.2"
},
"type": "module"
}
Main issue : my import { ... } from '@types/engine';
statements are not working, VSCode tells me that it cannot import type declaration
and recommend to use 'engine' instead of '@types/engine'
... ts(6137) module "/Users/.../monorepo/@types/engine/index"
Weird because it clearly indicates 'monorepo/@types/engine/index'
The @types/engine folder contains this package.json :
{
"name": "@types/engine",
"version": "1.0.0",
"types": "index.d.ts",
"main": "dist/index.js",
"scripts": {
"build": "tsc index.d.ts --outDir dist/"
},
"devDependencies": {
"typescript": "^5.6.2"
}
}
I have created inside an index.d.ts file with all the exports, and this type package is included in other packages like that : "@types/engine": "workspace:^1.0.0",
I am wondering if "@types" would not be a specific name/prefix that cannot be used for private/local packages...
Also how do I know if yarn is looking for sources OR for the transformed version of the local packages ?
My last concern about yarn install :
What is the correct way to install ? should I only use yarn install
inside the monorepo root folder ? Or should I use yarn workspace MyPackages install
for each package ? Or should I do both ?
Because I use nodeLinker: node-modules
, and I see node_modules/ folders in the root folder AND in each package folder except in the "Admin/" folder, given it uses specific packages (like MUI) I would expect to not see them in the node_modules of the root folder ?