nx-extensions icon indicating copy to clipboard operation
nx-extensions copied to clipboard

Vite: Transitive dependencies are not resolved

Open realityfilter opened this issue 3 years ago • 5 comments

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 avatar Feb 22 '22 09:02 realityfilter

@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 ^^'

DominikPieper avatar Feb 23 '22 09:02 DominikPieper

  • 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.

realityfilter avatar Feb 23 '22 09:02 realityfilter

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

DominikPieper avatar Feb 23 '22 09:02 DominikPieper

@realityfilter fighting this in another way right now. If my idea works hopefully it's done tomorrow

DominikPieper avatar Mar 24 '22 14:03 DominikPieper

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

Maximilianos avatar Mar 28 '22 21:03 Maximilianos