Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running madge from outside project directory shows empty dependencies with paths tsconfig option #430

Open
dyllandry opened this issue Jul 16, 2024 · 1 comment

Comments

@dyllandry
Copy link

Minimal reproducible example: https://github.com/dyllandry/vite-madge-mre

When working on a vue project and running madge from outside the project directory, madge shows missing imports when the import uses tsconfig's paths option.

This will correctly work when madge is run from inside the project:

$ ../madge/bin/cli.js src/main.js --ts-config tsconfig.json 
Processed 4 files (352ms) 

App.vue
  components/HelloWorld.vue
components/HelloWorld.vue
main.js
  App.vue
  style.css
style.css

But when run from outside the project, it doesn't work:

$ ./madge/bin/cli.js vite-madge-mre/src/main.js --ts-config vite-madge-mre/tsconfig.json --warning
Processed 3 files (272ms) (1 warning)

App.vue
main.js
  App.vue
  style.css
style.css

✖ Skipped 1 file

@/components/HelloWorld.vue

I've seen this issue #399 but I'm not sure what they set --basedir to to get it working. I've tried many different combinations.

I've gotten it working by setting in the project's tsconfig "baseUrl": "." but that could cause breaking behaviour in the project by favoring a relative import instead of one from node_modules.

@dyllandry
Copy link
Author

My current solution is when calling the madge module to provide a tsconfig object that uses my project's tsconfig and adds a baseUrl set to the path to the project's directory.

  const madgeResult = await madge(pathToMainJs, {
    baseDir: pathToProjectDir,
    tsConfig: {
      ...projectsTsconfig,
      compilerOptions: {
        ...projectsTsconfig.compilerOptions,
        baseUrl: pathToProjectDir,
      },
    },
  });

This works for now, but it can still cause breaking changes. If I understand the baseUrl docs correctly, if the project imports "my-module" it could now resolve to a local file "my-module.js" when they mean for it to resolve to a package in node_modules called "my-module". I don't think this is happening for any of my projects, but it is a reason why this solution isn't ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant