Apollo iOS:命令 /bin/sh 失败,退出代码为 1 |命令 PhaseScriptExecution 失败,退出代码非零

Apollo iOS: Command /bin/sh failed with exit code 1 | Command PhaseScriptExecution failed with a nonzero exit code

我遵循 installation tutorial by Apollo. And I totally confident that I did everything as is described in installation tutorial。但是,在项目构建过程中,我收到编译器错误,例如:

TypeError: Cannot read property 'length' of undefined

at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
at Object.runCommand (/usr/local/lib/node_modules/apollo- codegen/node_modules/yargs/lib/command.js:235:44)
at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)

Command /bin/sh failed with exit code 1

++ exec apollo-codegen generate --schema schema.json --output API.swift

TypeError: Cannot read property 'length' of undefined

at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
at Object.runCommand (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/lib/command.js:235:44)
at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

Command PhaseScriptExecution failed with a nonzero exit code

为什么我收到这个错误?

在花了很多时间和搜索之后,我明白了为什么会出现错误。感谢 @NiltiakSivadGitHub issue discussion

上的回答

Apollo script 试图在具有适当 queries 或 [= 的项目文件夹中查找扩展名为 .graphql 的文件20=]突变。如果它们不存在,您可能会出现上述错误。我认为 Apollo 团队应该在安装教程中警告他们的观众这种可能的情况!

所以,为了成功 运行 项目确保:

  • 您的 Apollo 版本apollo-codegen
  • 兼容
  • 您正确添加了Apollo script
  • 项目文件夹中有schema.json
  • 您的项目文件夹中有扩展名为 .graphql 的文件 包含适当的 schema.json querymutation