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

初始化Graph Studio遇代码生成失败:如何修复“找不到模块”错误?

解决Graph Studio初始化时yarn codegen报错问题

报错信息

无法从ABI和GraphQL Schema生成代码:命令执行失败:yarn codegen
warning ..\package.json: No license field
»   ModuleLoadError: [MODULE_NOT_FOUND] require failed to load
»   D:\Dapps\tryTheGraph\uniswap\node_modules@graphprotocol\graph-cli\dist\commands\codegen.js: Cannot find module './_version'

解决步骤

  • 清理依赖并重新安装

    1. 删除项目目录下的node_modules文件夹和yarn.lock文件
    2. 执行yarn cache clean清除yarn缓存
    3. 重新运行yarn install安装依赖,之后再尝试yarn codegen
  • 校验依赖版本兼容性
    确保package.json中@graphprotocol/graph-cli和@graphprotocol/graph-ts版本匹配,建议使用同大版本的官方推荐组合,例如:

    {
      "devDependencies": {
        "@graphprotocol/graph-cli": "^0.60.0",
        "@graphprotocol/graph-ts": "^0.31.0"
      }
    }
    

    修改后重新执行yarn install和yarn codegen

  • 消除license警告(可选)
    在项目根目录的package.json中添加许可证字段,比如:

    {
      "name": "your-subgraph-project",
      "license": "MIT",
      // 其他配置项
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 04:43:08