0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

EAS Buildでapp.jsonが読み込まれていない場合

Posted at

EAS Build で Config 情報を取得できない場合

エラー

以下のようなエラーが出力された、または 【現象】と同じケースで困っている方はぜひ以下をご覧ください

[PREBUILD] CommandError: Input is required, but 'npx expo' is in non-interactive mode.
[PREBUILD] Project must have a `ios.bundleIdentifier` set in the Expo config (app.json or app.config.js).
[PREBUILD] error Command failed with exit code 1.

はじめに

僕が個人で開発しているスマホアプリでは同じスマホに複数環境をインストールできる、かつ他ライブラリの都合上app.config.ts(js)で定義する訳にはいかなかったため、以下のように各環境毎に json 形式で定義し、ts-node を用いて app.json を生成するようにしています。

開発環境の用意

// 開発環境
const dev = {
  "slug": "xxx-dev",
  "scheme": "xxx-dev",
  "ios": {
    "bundleIdentifier": "xxx.yyy.zzz.dev"
  },
  "android": {
    "package": "xxx.yyy.zzz.dev"
  },
}
// 検証環境
const stg = {
  "slug": "xxx-stg",
  "scheme": "xxx-stg",
  "ios": {
    "bundleIdentifier": "xxx.yyy.zzz.stg"
  },
  "android": {
    "package": "xxx.yyy.zzz.stg"
  },
}
// 本番環境
const prod = {
  "slug": "xxx-prod",
  "scheme": "xxx-prod",
  "ios": {
    "bundleIdentifier": "xxx.yyy.zzz.prod"
  },
  "android": {
    "package": "xxx.yyy.zzz.prod"
  },
}

開発環境の起動

yarn devで開発環境を実行できます。
実際のコマンドは以下のようになっています。

package.json
scripts: {
  "dev": "yarn make:config:dev && APP_ENV=dev expo start --dev-client",
  "make:config:dev": "APP_ENV=dev ./node_modules/.bin/ts-node ./makeAppJson.ts", // 開発環境app.jsonの生成
  "make:config:stg": "APP_ENV=staging ./node_modules/.bin/ts-node ./makeAppJson.ts", // 検証環境app.jsonの生成
  "make:config:prod": "APP_ENV=production ./node_modules/.bin/ts-node ./makeAppJson.ts", // 本番環境app.jsonの生成
}

今回の現象と解決方法

【現象】

以下のように app.json の内容がビルドサーバーに含まれていないため、
PREBUILD フェーズで読み込みが行えないとエラーが発生していました。

[READ_APP_CONFIG] Using app configuration:
[READ_APP_CONFIG] {
  "name": "zzz",
  "slug": "zzz",
  "version": "1.0.0",
  "sdkVersion": "47.0.0",
  "platforms": [
    "ios",
    "android",
    "web"
  ],
  "currentFullName": "@aaa/zzz",
  "originalFullName": "@aaa/zzz"
}

(省略)

[PREBUILD] CommandError: Input is required, but 'npx expo' is in non-interactive mode.
[PREBUILD] Project must have a `ios.bundleIdentifier` set in the Expo config (app.json or app.config.js).
[PREBUILD] error Command failed with exit code 1.

【原因】

eas build は.gitignore を元にビルドサーバーに app.json を送信しているらしい。
なので.gitignore に app.json を追加しているとビルドサーバーに app.json が送信されていなくなっていた。

【解決方法】

git に app.json をコミットしたくないがビルドの度に.gitignore を編集するのは面倒な方は以下 2 の手順で解決できる

  1. .gitignore から app.json を除く
  2. .gitignore を.easignore にコピー & .easignore から app.json を除く

おわり

この指とまれというアプリを開発しています!
グループ管理に便利な様々な機能を開発・追加予定ですのでもしよければインストールしてみてください 🥳
【iOS/Android】https://konoyubitomare.app

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?