nx-extensions
nx-extensions copied to clipboard
Vite: Transitive dependencies are not resolved
Describe the bug Apps using libraries which are using other libraries are not resolved.
To Reproduce
A detailed bug report is filed for library vite-tsconfig-paths:
https://github.com/aleclarson/vite-tsconfig-paths/issues/47
Demo repository: https://github.com/realityfilter/bug-transitive-deps
Expected behavior
nx serve app will successfully serve the app
In the meantime we are resolving the dependencies manually:
const { readFileSync } = require('fs');
const { join } = require('path');
const calculateAlias = (rootPath) => {
const tsConfigFile = join(rootPath, 'tsconfig.base.json');
const tsConfig = JSON.parse(readFileSync(tsConfigFile).toString());
const alias = {};
Object.keys(tsConfig.compilerOptions.paths).forEach((key) => {
alias[key] = join(rootPath, tsConfig.compilerOptions.paths[key][0]);
});
return alias;
};
const workspaceAliases = () => {
const aliases: { [find: string]: string } = calculateAlias(rootDir);
return sources = Object.keys(aliases).map((key) => ({ find: key, replacement: aliases[key] }));
};
export default defineConfig({
resolve: {
alias: [...workspaceAliases()],
},
});
@realityfilter I saw your comment on the Bug report. You got it working with Nx I assume? The tsconfig.base.json is the default here so changig it could be hard ^^'
- We are still having a symlink to tsconfig.base.json because of an older, unrelated bug.
- Setting the loose option of vite-tsconfig-paths together with the symlink solved this issue.
- We need our own vite.config.ts because of vue. So no problem for us.
But with the current nx setup transitive dependencies do not work out of the box, unfortunately.
I'll take a look at that later. Maybe it's possible to make it configurable on their side so we can set it to tsconfig.base.json
@realityfilter fighting this in another way right now. If my idea works hopefully it's done tomorrow
I ran into this as well and have posted how I resolved it based on the notes in this thread and elsewhere in the following issue: https://github.com/aleclarson/vite-tsconfig-paths/issues/12#issuecomment-1081160667