pahen / madge

Create graphs from your CommonJS, AMD or ES6 module dependencies
MIT License
9.06k stars 317 forks source link

Typescript error when running madge on Ubuntu #363

Closed JackelynOliveira closed 1 year ago

JackelynOliveira commented 1 year ago

I'm having an error that seems to be typescript related when trying to run madge on an Ubuntu machine. It doesn't happen when I'm running it on macOS.

OS: Ubuntu 22.04 Node version: 16.19.1 Madge version: 5

.madgerc contents:

{
  "tsConfig": "tsConfig.json",
  "fileExtensions": ["js", "ts"],
  "excludeRegExp": ["^build\/"]
}

Command: madge --circular ./

yarn run v1.22.19
$ madge --circular ./
/<project_folder>/madge/node_modules/typescript/lib/typescript.js:28137
        if (!sourceFile.statements.length) {
                                   ^

TypeError: Cannot read properties of undefined (reading 'length')
    at convertToObjectWorker (<project_folder>/node_modules/madge/node_modules/typescript/lib/typescript.js:28137:36)
    at parseOwnConfigOfJsonSourceFile (<project_folder>/node_modules/madge/node_modules/typescript/lib/typescript.js:288[5]([...]#step:6:6)1:20)
    at parseConfig (<project_folder>/node_modules/madge/node_modules/typescript/lib/typescript.js:28758:13)
    at parseJsonConfigFileContentWorker (<project_folder>/node_modules/madge/node_modules/typescript/lib/typescript.js:28[6]([...]#step:6:7)05:28)
    at Object.parseJsonSourceFileConfigFileContent (<project_folder>/node_modules/madge/node_modules/typescript/lib/typescript.js:285[7]([...]#step:6:8)2:16)
    at Object.<anonymous> (<project_folder>/node_modules/madge/bin/cli.js:117:17)
    at Module._compile (node:internal/modules/cjs/loader:11[9]([...]#step:6:10)1:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:[10]([...]#step:6:11))
    at Module.load (node:internal/modules/cjs/loader:1069:32)
    at Function.Module._load (node:internal/modules/cjs/loader:904:[12]([...]#step:6:13))
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

Let me know if there's any other information you need.

Update: I was able to track down the cause of the problem. In the .madgerc file, there was a typo on the typescript file name (it should be tsconfig.json instead of tsConfig.json).

I'd suggest as a improvement, if possible, validating the provided file name to avoid misleading errors such as this.