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

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

Closed
KernAlan opened this issue Aug 26, 2024 · 13 comments · Fixed by expo/expo#31874
Closed

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

KernAlan opened this issue Aug 26, 2024 · 13 comments · Fixed by expo/expo#31874

Comments

@KernAlan
Copy link

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 KernAlan added the needs review Issue is ready to be reviewed by a maintainer label Aug 26, 2024
@KernAlan
Copy link
Author

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
Copy link
Member

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.

@szdziedzic szdziedzic added eas build needs more info and removed needs review Issue is ready to be reviewed by a maintainer labels Aug 27, 2024
@KernAlan
Copy link
Author

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.

@Jonatthu
Copy link

Jonatthu commented Sep 19, 2024

On my case, it has the same issue when I am console logging on the app.config.ts @brentvatne
Once I remove console.logs it goes away.
I still think should be fixed
image

@EJ132
Copy link

EJ132 commented Sep 20, 2024

Same here @Jonatthu @brentvatne it looks like logging to the console in app.config.ts causes the problem. Hopefully the underlying issue can still be addressed.

@jimmyphan
Copy link

@brentvatne I'm encountering the same issue as others when using console logs in app.config.ts. Removing the logs resolves the problem for me as well. It seems like there's an underlying issue here that should be looked at.

@szdziedzic
Copy link
Member

Hi,

It seems like the error you all describe comes from the EAS Update runtime version resolution logic, which is being run just after uploading the app archive to EAS and before actually starting the build. I believe that at the moment it uses the npx expo export command to resolve config and be compatible with many SDK versions at the same time. I believe what happens here is that parsing the npx expo export output fails when console logs are printed when resolving the config as well.

cc: @wschurman

@Jonatthu
Copy link

@szdziedzic Yes, this has been like that for a long time, and we use dotenv which outputs a couple of console.logs I cannot remove, so my CI keeps failing!

@Jonatthu
Copy link

Jonatthu commented Oct 2, 2024

@brentvatne @szdziedzic any updates?

@wschurman
Copy link
Member

Contributors of expo-updates are going to be discussing this soon and will hopefully have a fix soon as well. For now, removing the console.logs is the only option.

@Jonatthu
Copy link

Jonatthu commented Oct 2, 2024

image

Please this is blocking my CI :/

@wschurman
Copy link
Member

Planning to cherry-pick the above PR into SDK 51 to fix. Will post on this thread when ready to use.

@wschurman
Copy link
Member

Fix was released in expo-updates 0.25.27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants
@wschurman @Jonatthu @jimmyphan @EJ132 @szdziedzic @KernAlan and others