Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eas build fail Unexpected token 'E', "Environmen"... is not valid JSON #2500

Closed
kaleb-dev opened this issue Aug 19, 2024 · 6 comments
Closed
Assignees
Labels
eas build eas update needs review Issue is ready to be reviewed by a maintainer

Comments

@kaleb-dev
Copy link

kaleb-dev commented Aug 19, 2024

Build/Submit details page URL

No response

Summary

I'm encountering an error when attempting to build my Expo React Native app using EAS Build for iOS. When running the command eas build --platform ios --profile preview, the build process fails with a JSON parsing error: "Unexpected token 'E', "Environmen"... is not valid JSON". This occurs despite having a properly configured eas.json file with different build profiles, including a "preview" profile that sets APP_VARIANT to "stage". My project uses a custom app.config.ts file to configure the app based on different environments, determined by an environmentUtil function. Ran the same code on another developers system and no error

Managed or bare?

Managed

Environment

expo-env-info 1.2.0 environment info:
System:
OS: macOS 14.6.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
Watchman: 2024.08.12.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.15.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5
Android SDK:
API Levels: 34
Build Tools: 30.0.3, 33.0.1, 34.0.0, 35.0.0, 35.0.0
System Images: android-28 | Google APIs ARM 64 v8a, android-UpsideDownCakePrivacySandbox | Google Play ARM 64 v8a
IDEs:
Android Studio: 2024.1 AI-241.15989.150.2411.11948838
Xcode: 15.4/15F31d - /usr/bin/xcodebuild
npmPackages:
expo: ^51.0.28 => 51.0.28
expo-router: ~3.5.23 => 3.5.23
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.74.5 => 0.74.5
react-native-web: ~0.19.6 => 0.19.12
npmGlobalPackages:
eas-cli: 10.2.3
Expo Workflow: bare

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check for issues with metro config
✔ Check for app config fields that may not be synced in a non-CNG project
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check native tooling versions
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that native modules use compatible support package versions for installed Expo SDK
✔ Check that packages match versions required by installed Expo SDK

Didn't find any issues with the project!

Error output

Compressing project files and uploading to EAS Build. Learn more
✔ Uploaded to EAS
Unexpected token 'E', "Environmen"... is not valid JSON
SyntaxError: Unexpected token 'E', "Environmen"... is not valid JSON
at JSON.parse ()
at resolveRuntimeVersionAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/project/resolveRuntimeVersionAsync.js:22:43)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async createAndMaybeUploadFingerprintAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/build/build.js:431:36)
at async prepareBuildRequestForPlatformAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/build/build.js:81:29)
at async prepareIosBuildAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/build/ios/build.js:60:12)
at async startBuildAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/build/runBuildAndSubmit.js:286:33)
at async prepareAndStartBuildAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/build/runBuildAndSubmit.js:274:19)
at async runBuildAndSubmitAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/build/runBuildAndSubmit.js:102:49)
at async Build.runAsync (/Users/kalebtessema/.nvm/versions/node/v20.16.0/lib/node_modules/eas-cli/build/commands/build/index.js:42:9)

Reproducible demo or steps to reproduce from a blank project

{
  "cli": {
    "version": ">= 5.2.0",
    "appVersionSource": "remote"
  },
  "build": {
    "development": {
      "autoIncrement": true,
      "developmentClient": true,
      "distribution": "internal",
      "env": {
        "APP_VARIANT": "dev"
      },
      "channel": "development"
    },
    "development-simulator": {
      "autoIncrement": true,
      "developmentClient": true,
      "distribution": "internal",
      "ios": {
        "simulator": true
      },
      "env": {
        "APP_VARIANT": "dev"
      },
      "channel": "development-simulator"
    },
    "preview": {
      "autoIncrement": true,
      "distribution": "internal",
      "env": {
        "APP_VARIANT": "stage"
      },
      "channel": "preview"
    },
    "production": {
      "autoIncrement": true,
      "env": {
        "APP_VARIANT": "prod"
      },
      "channel": "production"
    }
  },
  "submit": {
    "production": {},
    "preview": {
      "ios": {
        "ascAppId": `{appID}`
        "bundleIdentifier": `{bundleID}`
      }
    }
  }
}
import "ts-node/register";
import { ExpoConfig, ConfigContext } from "expo/config";
import { environmentUtil } from "./utils/enviroment";

const environment: "staging" | "production" | "localhost" = environmentUtil();

export default ({ config }: ConfigContext): ExpoConfig => {
  const appConfig: ExpoConfig = {
    ...config,
    icon: "./assets/images/betaIcon.png",
    android: {
      ...config.android,
      googleServicesFile: "./google-services.json",
      package: `{bundleID}`,
    },
    ios: {
      ...config.ios,
      googleServicesFile:
        process.env.GoogleService_Info_dev || "./GoogleService-Info-dev.plist",
      bundleIdentifier: `{bundleID}`
    },
    runtimeVersion: {
      policy: "sdkVersion",
    },
    extra: {
      eas: {
        projectId: `{projectID}`,
      },
    },
    updates: {
      url: `{projectID}`
    },
  };

  if (environment === "staging") {
    return {
      ...appConfig,
      android: {
        googleServicesFile: "./google-services.json",
        package: `{bundleID}`,
      },
      ios: {
        googleServicesFile:
          process.env.GoogleService_Info_stage ||
          "./GoogleService-Info-stage.plist",
        bundleIdentifier: `{bundleID}`,
      },
      runtimeVersion: {
        policy: "sdkVersion",
      },
      extra: {
        eas: {
          projectId: `{projectID}`,
        },
      },
      updates: {
        url: "`{projectID}`
      },
    };
  }

  if (environment === "production") {
    return {
      ...appConfig,
      icon: "./assets/images/icon.png",
      android: {
        googleServicesFile: "./google-services.json",
        package: "com.mycorp.myapp",
      },
      ios: {
        googleServicesFile: "./GoogleService-Info-prod.plist",
        bundleIdentifier: "com.mycorp.myapp",
      },
      extra: {
        eas: {
          projectId: `{projectID}`,
        },
      },
    };
  }

  return appConfig;
};

Running eas build --platform ios --profile preview , or any other eas build command i get the following error

@kaleb-dev kaleb-dev added the needs review Issue is ready to be reviewed by a maintainer label Aug 19, 2024
@kaleb-dev
Copy link
Author

Issue has to do with expo-update, after removing it build went through

@szdziedzic
Copy link
Member

Hi @kaleb-dev,

What does your environmentUtil() function do? Does it print some text to stdout?

CC: @wschurman
It seems to come from

const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(
projectDir,
['runtimeversion:resolve', '--platform', platform, '--workflow', workflow, ...extraArgs],
{ env, cwd }
);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);

@kaleb-dev
Copy link
Author

kaleb-dev commented Aug 19, 2024

export const environmentUtil = (): "staging" | "production" | "localhost" => {
  const environment: String | boolean = process.env.APP_VARIANT || "localhost";
  console.log("Environment:", environment); // Add this line for debugging

  if (environment === "stage") {
    return "staging";
  }
  if (environment === "prod") {
    return "production";
  }
  return "localhost";
};

utility function to build for different environments based on EAS env configuration in my eas.json

@wschurman
Copy link
Member

If that function runs during app json evaluation, the console.log will print to stdout. During expo-updates build step, it runs a command and extracts the stdout as JSON. Removing the console.log should fix this.

@vinitcs
Copy link

vinitcs commented Sep 18, 2024

I'm getting the uncheck for
"Check for app config fields that may not be synced in a non-CNG project"

How do I solved it?

@lindsaymacvean
Copy link

For "Check for app config fields that may not be synced in a non-CNG project"

Took me a minute but realised the easiest solution for this issue is to just remove android and ios directories from git (and add them to the .gitignore so they dont come back). You can still build locally, its just EAS doesnt like those directories to be fixed in your git repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eas build eas update needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

5 participants