Repository created with the purpose to test a common typescript issue with monorepos.
workspace (ts-monorepo-issue-example)
- node_modules
- module-b (linked)
- src
- index.js
- packages
- module-b (linked globally)
- node_modules
- ts-typelib-example (v2.0.0)
- module-a
- node_modules
- ts-typelib-example (v1.0.0)
- src
- package.json
- node_modules
- src
- package.json
- node_modules
- ts-typelib-example
- node_modules
- src
- package.json
- module-b (linked globally)
- package.json
When 2 major versions of the same module (which changes a type) are installed in different packages, TypeScript cache does not make distinctions. It will take, the first module found as the only one module in the project ignoring nodejs dependencies resolution standard also explained in TypeScript documentation.
This resolution works when the project is a monolith style application (single repository with only 1 package.json) where every dependency will be installed in only 1 version. Actually transpilers (like webpack), npmjs and nodejs also supports monorepos and is helpful while working with npm link.
- Clone repository
- npm install (for installing modules in repository)
- Link module-b to the project (this step is to simulate we are working with this module in local repository)
- Execute TypeScript compiler (npm run typescript)
A fail will appear in src/index.ts in the project. This fail is related to microsoft/TypeScript#29221 in TypeScript official github.
ts-issue-module-a ts-issue-module-b ts-typelib-example
Parent project:
{
"exclude": ["node_modules"],
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"skipLibCheck": true,
"declaration": true,
"strict": true,
"isolatedModules": false,
"esModuleInterop": true,
"jsx": "preserve",
"module": "commonjs",
"preserveSymlinks": true
}
}
Modules:
{
"exclude": ["node_modules"],
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"skipLibCheck": true,
"declaration": true,
"strict": true,
"isolatedModules": false,
"esModuleInterop": true,
"jsx": "preserve",
"module": "commonjs"
}
}