I have the following setup for the npm monorepo: https://github.com/ChristianKernDev/monorepo_playground
Everything works as expected, except the tsc
command, which shows the following error:
../common/src/index.ts:1:17 - error TS2307: Cannot find module 'test/a' or its corresponding type declarations.
This means, that the compiler can not correctly import direct paths in a submodule. How can i fix this?
There are multiple points:
npm link
. See relevant docs. Just running npm install
is enough.common
lib in app/tsconfig.json
:{
"extends": "../tsconfig.json",
"compilerOptions": {
...
},
"references": [
{ "path": "../common" }
],
"include": [
...
]
}
noEmit
in base tsconfig with emitDeclarationOnly
so that the type declarations for 'common' lib are generated (credit).composite
to true
to enable declaration
.{
"compilerOptions": {
...
"emitDeclarationOnly": true,
"composite": true
},
}
npm run --workspaces