You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows系统下Madge工具相对路径通配符无法正常使用问题

解决Windows 11下Madge glob路径报错问题

你遇到的问题根源在于Windows默认的CMD/PowerShell不支持类Unix的** glob通配符展开,而Madge本身不会自动处理这类通配符,它依赖shell把glob转换成具体的文件列表。用具体路径时不需要展开操作,所以能正常运行。

下面是几种可行的解决办法:

  • 调整glob写法并让Node.js处理通配符:把路径用双引号包裹,同时简化glob模式(src/**/**.ts里的**重复了,**已代表任意子目录,直接跟*.ts即可),修改后的命令:

    madge --circular "src/**/*.ts"
    

    这样会由Node.js的glob模块自动处理路径展开,而非交给Windows shell。

  • 用PowerShell生成文件列表传入:如果上面的方法无效,可通过PowerShell先获取所有目标.ts文件,再传给Madge:

    madge --circular (Get-ChildItem -Recurse -Path src -Filter *.ts).FullName
    
  • 切换到WSL运行命令:WSL的Shell(比如Bash)完全支持类Unix的glob语法,直接在WSL里执行madge --circular src/**/*.ts就能正常工作。

  • 写Node.js脚本调用Madge API:如果命令行方式始终有问题,可创建一个脚本文件(比如check-circular.js):

    const madge = require('madge');
    
    madge('src/**/*.ts', { circular: true })
      .then((result) => {
        result.circular();
      })
      .catch((error) => {
        console.error('Error:', error);
      });
    

    然后运行node check-circular.js,Madge会通过自身的glob逻辑直接匹配文件。

内容的提问来源于stack exchange,提问作者Sebastian_B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 06:45:27