I am working on an Nx monorepo for my SolidJS frontend app that depends on my own libraries (some are pure TypeScript, others are SolidJS libraries).
When I run “nx serve myMainApp” it works well, the path aliases are correctly resolved (they are defined both in tsconfig.base.json and also in the vite.config.ts file of myMainApp). They are referencing the source files directly (for example: “@myOrg/myLib”: [“libs/myLib/src/index.ts”]).
But I would like to configure the project for production builds. So I want my path aliases to reference the libs’ build outputs in dist/, instead of the source files.
In order to do that, I override the path aliases of the tsconfig.base.json in the tsconfig.lib.json of myLibB (which depends on myLibA, and myLibA seems to be built correctly):
"compilerOptions": {
"paths": {
"@myOrg/myLibA": ["../../dist/libs/myLibA"]
}
}
But when I try to do nx build myLibB, I have the following TSError: error TS2307: Cannot find module ‘@myOrg/myLibA’ or its corresponding type declarations.
I also set the path alias to myLibA in the vite.config.ts of myLibB, and after checking the path to the build output seems to be correct:
resolve: {
alias: {
'@myOrg/myLibA': path.resolve(__dirname, '../../dist/libs/myLibA'),
}
}
There is indeed an index.d.ts file in the dist/libs/myLibA folder, and it exports the other .d.ts files.
I am new to all this. Can you please help me solve it and build my library?