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 failed #6144

Closed
darix795 opened this issue Sep 20, 2023 · 10 comments · Fixed by #6266
Closed

EAS build failed #6144

darix795 opened this issue Sep 20, 2023 · 10 comments · Fixed by #6266

Comments

@darix795
Copy link

darix795 commented Sep 20, 2023

How frequently does the bug occur?

  • select --

Description

I using Expo 49 with version 12.1 of realm. During android development with command npx expo run:android everything works fine, but when EAS build start error Unable to resolve module ../realm-constants.json occurs. On iOS looks good and build succeded.

Stacktrace & log output

[RUN_GRADLEW] warning: Bundler cache is empty, rebuilding (this may take a minute)
[RUN_GRADLEW] Error: Unable to resolve module ../realm-constants.json from /private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/realm/dist/bundle.react-native.js:
[RUN_GRADLEW] None of these files exist:
[RUN_GRADLEW] * ../../node_modules/realm/realm-constants.json(.native|.android.jsx|.native.jsx|.jsx|.android.js|.native.js|.js|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.cjs|.native.cjs|.cjs|.android.json|.native.json|.json|.android.mjs|.native.mjs|.mjs)
[RUN_GRADLEW] * ../../node_modules/realm/realm-constants.json/index(.native|.android.jsx|.native.jsx|.jsx|.android.js|.native.js|.js|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.cjs|.native.cjs|.cjs|.android.json|.native.json|.json|.android.mjs|.native.mjs|.mjs)
[RUN_GRADLEW]   4 | var reactNative = require('react-native');
[RUN_GRADLEW]   5 | var bson = require('bson');
[RUN_GRADLEW] > 6 | var realmConstants_json = require('../realm-constants.json');
[RUN_GRADLEW]     |                                    ^
[RUN_GRADLEW]   7 |
[RUN_GRADLEW]   8 | function _interopNamespaceDefault(e) {
[RUN_GRADLEW]   9 |   var n = Object.create(null);
[RUN_GRADLEW] Error: Unable to resolve module ../realm-constants.json from /private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/realm/dist/bundle.react-native.js: 
[RUN_GRADLEW] None of these files exist:
[RUN_GRADLEW]   * ../../node_modules/realm/realm-constants.json(.native|.android.jsx|.native.jsx|.jsx|.android.js|.native.js|.js|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.cjs|.native.cjs|.cjs|.android.json|.native.json|.json|.android.mjs|.native.mjs|.mjs)
[RUN_GRADLEW]   * ../../node_modules/realm/realm-constants.json/index(.native|.android.jsx|.native.jsx|.jsx|.android.js|.native.js|.js|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.cjs|.native.cjs|.cjs|.android.json|.native.json|.json|.android.mjs|.native.mjs|.mjs)
[RUN_GRADLEW]   4 | var reactNative = require('react-native');
[RUN_GRADLEW]   5 | var bson = require('bson');
[RUN_GRADLEW] > 6 | var realmConstants_json = require('../realm-constants.json');
[RUN_GRADLEW]     |                                    ^
[RUN_GRADLEW]   7 |
[RUN_GRADLEW]   8 | function _interopNamespaceDefault(e) {
[RUN_GRADLEW]   9 |   var n = Object.create(null);
[RUN_GRADLEW]     at ModuleResolver.resolveDependency (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:114:15)
[RUN_GRADLEW]     at DependencyGraph.resolveDependency (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
[RUN_GRADLEW]     at Object.resolve (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/lib/transformHelpers.js:169:21)
[RUN_GRADLEW]     at Graph._resolveDependencies (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/DeltaBundler/Graph.js:473:35)
[RUN_GRADLEW]     at Graph._processModule (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/DeltaBundler/Graph.js:261:38)
[RUN_GRADLEW]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[RUN_GRADLEW] at async Graph._addDependency (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/DeltaBundler/Graph.js:372:20)
[RUN_GRADLEW]     at async Promise.all (index 0)
[RUN_GRADLEW]     at async Graph._processModule (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/DeltaBundler/Graph.js:322:5)
[RUN_GRADLEW]     at async Graph._addDependency (/private/var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/7856c976-98fb-40d8-a585-24322bc8e477/build/node_modules/metro/src/DeltaBundler/Graph.js:372:20)
[RUN_GRADLEW] > Task :app:createBundleReleaseJsAndAssets
[RUN_GRADLEW] FAILED
[RUN_GRADLEW] > Task :app:writeReleaseApplicationId
[RUN_GRADLEW] > Task :app:analyticsRecordingRelease
[RUN_GRADLEW] FAILURE: Build failed with an exception.
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] Execution failed for task ':app:createBundleReleaseJsAndAssets'.
[RUN_GRADLEW] > Process 'command 'node'' finished with non-zero exit value 1
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] * Get more help at https://help.gradle.org
[RUN_GRADLEW] Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
[RUN_GRADLEW] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
[RUN_GRADLEW] See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings
[RUN_GRADLEW] BUILD FAILED
[RUN_GRADLEW] in 56s
[RUN_GRADLEW] 19 actionable tasks: 19 executed
[RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

Build failed
Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
npx exited with non-zero code: 1
    Error: build command failed.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Can you reproduce the bug?

Always

Reproduction Steps

Simply run npx [email protected] build

Version

12.1.0

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

android

Build environment

expo@49
[email protected]
[email protected]

Cocoapods version

No response

@kneth
Copy link
Contributor

kneth commented Sep 25, 2023

@darix795 Thank you for reporting. The file is generated during installation through a post-install script. Could you check if node_modules/realm/realm-constants.json exists? It will help us debug the issue.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Sep 25, 2023
@darix795
Copy link
Author

darix795 commented Sep 26, 2023

Yes, I confirm existing node_modules/realm/realm-constants.json. I use monorepo so file exist in node_modules on root folder, while expo app is locate in apps/mobile folder.

During test I've try to change babel module resolution. I try to add realm to alias object, but this solution doesn't work.
Following the current configuration:

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      [
        "module-resolver",
        {
          alias: {
            "@fieldz/components": "./components",
            "@fieldz/hooks": "./hooks",
            "@fieldz/navigation": "./navigation",
            "@fieldz/models": "./models",
            "@fieldz/utils": "./utils",
            "@fieldz/jobs": "./jobs",
          },
          extensions: [".ios.js", ".android.js", ".js", ".ts", ".tsx", ".json"],
        },
      ],
      [
        "@tamagui/babel-plugin",
        {
          components: ["tamagui"],
          config: "./tamagui.config.ts",
          logTimings: true,
        },
      ],
      "macros",
      "react-native-reanimated/plugin",
    ],
    env: {
      production: {
        plugins: [["transform-remove-console", { exclude: ["error", "warn"] }]],
      },
    },
  };
};

I noticed that, opposite write in issue, on cloud build everything work fine. This issue happening only EAS local build both platform android and ios.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Sep 26, 2023
@timur-svoboda
Copy link

@darix795

To successfully build the application, dependencies must be installed in the application folder (apps/mobile in your case). The workspace should contain the eas-build-pre-install.mjs script, which is responsible for modifying the package.json file inside the application folder before installing dependencies during the build process. It is possible that the script is not functioning correctly or not running at all. To troubleshoot this issue, examine the logs for the [READ_PACKAGE_JSON] step to determine which package.json file is being used for the build. You can also check the node_modules folder inside the application folder to see what was actually installed.

@darix795
Copy link
Author

I try various build and i noticed that on build folder (ex. /var/folders/dt/pxn1rj795kbfflp3xp2l94rw0000gn/T/eas-build-local-nodejs/8ffaaf39-05fe-41de-baf6-c4ea9d8156ef/build/) file realm-constants.json not exist. When i run yarn install on dev mode that exists under node_module/realm.
Maybe eas not copy json file. During this day i will try to found cause.

@darix795
Copy link
Author

darix795 commented Sep 30, 2023

Seems that on eas installation phase file not copy on node_modules folder. I don't know if this is a realm or eas issue. So i write following script as workaround to execute on eas-build-post-install

import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Workaround
const jsonContent = `{"REALM_ANONYMIZED_BUNDLE_ID":"tkgif/+3l1e9wStGJp2TOngAK3UcQ2u7OM8ZYJU5JYo="}`;
const constantFileName = "realm-constants.json";
const realmPath = "../../../node_modules/realm";
const constantPath = path.join(__dirname, realmPath, constantFileName);

if (!fs.existsSync(constantPath)) {
  fs.writeFile(constantPath, jsonContent, { flag: "wx" }, function (err) {
    if (err) throw err;
  });
}

Probably yarn, npm or eas configuration on my computer is broken somewhere, because on cloud eas build everything works fine.

@fhb191309
Copy link

I'm currently having the same issue with my ios build.
node_modules/realm/realm-constants.json does not exist. Any suggestions how to fix this ?

@darix795
Copy link
Author

darix795 commented Oct 3, 2023

Seems that on eas installation phase file not copy on node_modules folder. I don't know if this is a realm or eas issue. So i write following script as workaround to execute on eas-build-post-install

import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Workaround
const jsonContent = `{"REALM_ANONYMIZED_BUNDLE_ID":"tkgif/+3l1e9wStGJp2TOngAK3UcQ2u7OM8ZYJU5JYo="}`;
const constantFileName = "realm-constants.json";
const realmPath = "../../../node_modules/realm";
const constantPath = path.join(__dirname, realmPath, constantFileName);

if (!fs.existsSync(constantPath)) {
  fs.writeFile(constantPath, jsonContent, { flag: "wx" }, function (err) {
    if (err) throw err;
  });
}

Probably yarn, npm or eas configuration on my computer is broken somewhere, because on cloud eas build everything works fine.

@fhb191309 meanwhile waiting fix you can use this workaround. Create a .mjs file, copy path and past into eas-build-post-install locate under scripts package.json on your app folder.

@AdamGerthel
Copy link

I have the same issue - also using Expo 49 with Realm 12 (12.2.1). It doesn't happen when built in EAS Cloud, but it happens when I make local builds using eas with the --local flag.

@wesvance
Copy link

wesvance commented Nov 19, 2023

Just to add additional info; I'm running into this as well using Expo 49 and all Realm 12 versions
Downgrading Realm to version 11.10.2 works with eas --local
Any version of 12, from 12.0.0 to 12.3.0, shows the Unable to resolve module ../realm-constants.json build error.

The script by @darix795 worked well as a temp fix- just update the 'realmPath' to match where your node_modules folder is, for me in a Expo app, the package.json script and the node_modules are on the same level so mine is const realmPath = "./node_modules/realm";

@kneth
Copy link
Contributor

kneth commented Nov 24, 2023

Version 12.3.1 has a fix for this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants