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

运行yarn graphql-codegen init报Unknown argument: init错误如何解决

问题原因

你的项目依赖中存在冲突的graphql-codegen相关包:

  • 废弃的旧版本包 graphql-codegen@0.4.0:该包早已停止维护,本身不支持init参数,执行yarn graphql-codegen时yarn会优先匹配该旧包的命令,因此抛出未知参数错误。
  • 官方新版包 @graphql-codegen/cli@2.1.1 是正确的依赖,但被旧包冲突覆盖无法被正确调用。

解决步骤

  1. 卸载废弃的旧版本包,执行如下命令:
yarn remove graphql-codegen
  1. 选择以下任意一种方式调用新版cli执行初始化即可:
  • 直接调用新版cli完整包名:
yarn @graphql-codegen/cli init
  • 在package.json的scripts字段中新增配置:
{
  "scripts": {
    "codegen": "graphql-codegen"
  }
}

配置完成后执行以下命令即可:

yarn codegen init

异常排查

如果完成以上操作后仍存在问题,删除项目中的node_modules文件夹和yarn.lock文件,重新执行yarn install安装依赖即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 23:36:04