expo / eas-cli

Fastest way to build, submit, and update iOS and Android apps
https://docs.expo.dev/eas/
MIT License
772 stars 81 forks source link

✔ Uploaded to EAS --> Unexpected token D in JSON at position 1 #2515

Open KernAlan opened 2 weeks ago

KernAlan commented 2 weeks ago

Build/Submit details page URL

https://expo.dev/accounts/kernalan/projects/lifesage

Summary

Running eas build --platform ios --profile development triggers a json parsing error as soon as the archive hits the EAS server:

Managed or bare?

Managed

Environment

  expo-env-info 1.2.0 environment info:
    System:
      OS: Windows 11 10.0.22631
    Binaries:
      Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
      npm: 10.8.1 - ~\AppData\Roaming\npm\npm.CMD
    npmPackages:
      expo: ~51.0.31 => 51.0.31
      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.10 => 0.19.12
    Expo Workflow: managed
✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check native tooling versions
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for app config fields that may not be synced in a non-CNG project
✔ Check npm/ yarn versions
✔ Check for issues with metro config
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that packages match versions required by installed Expo SDK
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!

Error output

Compressing project files and uploading to EAS Build. Learn more: https://expo.fyi/eas-build-archive
✔ Uploaded to EAS
Unexpected token D in JSON at position 1
    Error: build command failed.

Reproducible demo or steps to reproduce from a blank project

  1. Run eas build --platform ios --profile development
  2. Encounter the error
KernAlan commented 2 weeks ago

I spent a few hours trying to simplify my setup, and only after removing a dynamic configuration function in my app.config.json did this it fix the issue. I removed the dynamic configuration there in favor of an almost entirely static file.

szdziedzic commented 2 weeks ago

Hi @KernAlan,

Can you share your dynamic config setup with me? Also, I believe that running a failing command with EXPO_DEBUG=1 would print a whole stack trace of the error giving us more info about the issue.

KernAlan commented 2 weeks ago

Here was the problematic app.config.json:

const path = require("path");
const dotenv = require("dotenv");

module.exports = () => {
  // Determine which .env file to use
  const envPath = process.env.EAS_BUILD
    ? ".env.production"
    : process.env.NODE_ENV === "production"
    ? ".env.production"
    : ".env.development";

  console.log(`[DEBUG] Attempting to load environment file: ${envPath}`);

  const result = dotenv.config({ path: path.resolve(__dirname, envPath) });

  if (result.error) {
    console.error(`[ERROR] Failed to load ${envPath}:`, result.error);
  } else {
    console.log(`[INFO] Successfully loaded ${envPath}`);
  }

  console.log("[DEBUG] Environment variables in app.config.js:", {
    API_BASE_URL: process.env.API_BASE_URL,
    NODE_ENV: process.env.NODE_ENV,
  });

  const requiredVars = [
    "FIREBASE_API_KEY",
    "FIREBASE_AUTH_DOMAIN",
    "FIREBASE_PROJECT_ID",
    "FIREBASE_STORAGE_BUCKET",
    "FIREBASE_MESSAGING_SENDER_ID",
    "FIREBASE_APP_ID",
    "API_BASE_URL",
  ];

  requiredVars.forEach((varName) => {
    if (!process.env[varName]) {
      throw new Error(`Missing required environment variable: ${varName}`);
    }
  });

  return {
    expo: {
      name: "lifesage",
      scheme: "lifesage",
      slug: "lifesage",
      version: "1.0.1",
      orientation: "portrait",
      icon: "./assets/icon.png",
      userInterfaceStyle: "light",
      splash: {
        image: "./assets/splash.png",
        resizeMode: "contain",
        backgroundColor: "#ffffff",
      },
      assetBundlePatterns: ["**/*"],
      ios: {
        supportsTablet: true,
        bundleIdentifier: "com.kernalan.lifesage",
        buildNumber: "1",
        googleServicesFile: "./GoogleService-Info.plist",
        entitlements: {
          "aps-environment": "production",
        },
        podfileProperties: {
          "use_modular_headers!": true,
          "use_frameworks!": "static",
        },
        usesAppleSignIn: true,
      },
      android: {
        adaptiveIcon: {
          foregroundImage: "./assets/adaptive-icon.png",
          backgroundColor: "#ffffff",
        },
        package: "com.kernalan.lifesage",
        versionCode: 1,
      },
      web: {
        favicon: "./assets/favicon.png",
        bundler: "metro",
      },
      plugins: [
        "expo-router",
        [
          "expo-build-properties",
          {
            ios: {
              useFrameworks: "static",
            },
          },
        ],
      ],
      extra: {
        eas: {
          projectId: "ad20d820-991c-44ec-8528-26af05ab9834",
        },
        FIREBASE_API_KEY: process.env.FIREBASE_API_KEY,
        FIREBASE_AUTH_DOMAIN: process.env.FIREBASE_AUTH_DOMAIN,
        FIREBASE_PROJECT_ID: process.env.FIREBASE_PROJECT_ID,
        FIREBASE_STORAGE_BUCKET: process.env.FIREBASE_STORAGE_BUCKET,
        FIREBASE_MESSAGING_SENDER_ID: process.env.FIREBASE_MESSAGING_SENDER_ID,
        FIREBASE_APP_ID: process.env.FIREBASE_APP_ID,
        FIREBASE_MEASUREMENT_ID: process.env.FIREBASE_MEASUREMENT_ID,
        API_BASE_URL: process.env.API_BASE_URL,
      },
      owner: "kernalan",
    },
  };
};

I haven't been able to test more, but I suspect EAS expects an object, not a function wrapper. I used the function to be able to do dynamic swapping of env variables here, but getting rid of that approach fixes the issue.