pahen/madge

Typescript baseUrl "./" not recognized

Aperta

#317 aperta il 22 mag 2022

 (0 commenti) (9 reazioni) (0 assegnatari)JavaScript (322 fork)batch import
cligood first issue

Metriche repository

Star
 (8058 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

With tree structure:

.
├── main.ts
├── package-lock.json
├── package.json
├── tsconfig.json
└── utils
    ├── index.ts
    └── toUpper.ts

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "baseUrl": "."
  },
  "include": ["**/*.ts"],
  "exclude": ["node_modules"]
}

code:

// utils/toUpper.ts
export const toUpper = (str: string) => {
  return str.toUpperCase();
};

// utils/index.ts
export * from "./toUpper";

// main.ts
import { toUpper } from "utils"; // notice i am not using here ./utils but counting on typescripts baseUrl value
console.log(toUpper("madge"));

and when I run npx madge --ts-config ./tsconfig.json --extensions ts --warning --circular ./, I will get result

Processed 3 files (412ms) (1 warning)

✔ No circular dependency found!

✖ Skipped 1 file

utils

Why is my utils/index.ts skipped? I noticed if I change tsconfig's baseUrl to the result of pwd in the same dir as tsconfig.json, like so

    "baseUrl": "/Users/testing/typescript/madge"

then utils/index.ts won't be skipped and everything would work fine, or if I would restructure main.ts and utils inside src and set baseUrl to ./src it would also work fine.

How can I make madge with tsconfig's "baseUrl": "." to not skip utils?

Guida contributor