初始化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'
解决步骤
清理依赖并重新安装
- 删除项目目录下的
node_modules文件夹和yarn.lock文件 - 执行
yarn cache clean清除yarn缓存 - 重新运行
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
相关产品推荐
相关产品推荐

