[EAS Build] Gradle build failed with unknown error: TypeError: Cannot read property 'transformFile' of undefined

Hi all,

I’ve done as much research as I possibly can, and I really don’t have a clue as to what im doing wrong here - when running eas build --platform android The project build fails;

> Task :app:bundleReleaseJsAndAssets
649
TypeError: Cannot read property 'transformFile' of undefined
650
at /build/workingdir/build/client/app/public/node_modules/metro/src/Bundler.js:91:34
651
    at Generator.next (<anonymous>)
652
    at asyncGeneratorStep (/build/workingdir/build/client/app/public/node_modules/metro/src/Bundler.js:14:24)
653
    at _next (/build/workingdir/build/client/app/public/node_modules/metro/src/Bundler.js:34:9)
654
[stderr] Failed to construct transformer:  Error: ENOENT: no such file or directory, stat '/build/workingdir/build/node_modules'
655
[stderr]     at Object.statSync (fs.js:1086:3)
656
[stderr]     at Object.statSync (/build/workingdir/build/client/app/public/node_modules/graceful-fs/polyfills.js:308:16)
657
[stderr]     at verifyRootExists (/build/workingdir/build/client/app/public/node_modules/metro/src/DeltaBundler/Transformer.js:249:13)
658
[stderr]     at Array.forEach (<anonymous>)
659
[stderr]     at new Transformer (/build/workingdir/build/client/app/public/node_modules/metro/src/DeltaBundler/Transformer.js:123:31)
660
[stderr]     at /build/workingdir/build/client/app/public/node_modules/metro/src/Bundler.js:54:29 {
661
[stderr]   errno: -2,
662
[stderr]   syscall: 'stat',
663
[stderr]   code: 'ENOENT',
664
[stderr]   path: '/build/workingdir/build/node_modules'
665
[stderr] }
666
[stderr] error Cannot read property 'transformFile' of undefined. Run CLI with --verbose flag for more details.
667
> Task :app:bundleReleaseJsAndAssets FAILED
668
> Task :app:bundleReleaseJsAndAssets_SentryUpload_1 FAILED
669
Processing react-native sourcemaps for Sentry upload.
670
> Task :app:bundleReleaseJsAndAssets_SentryUploadCleanUp SKIPPED
671
[stderr] error: No such file or directory (os error 2)
672
[stderr] Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
673
[stderr] Please attach the full debug log to all bug reports.
674
> Task :unimodules-core:compileReleaseKotlin
675
[stderr] FAILURE: Build completed with 2 failures.
676
[stderr] 1: Task failed with an exception.
677
[stderr] -----------
678
[stderr] * What went wrong:
679
[stderr] Execution failed for task ':app:bundleReleaseJsAndAssets'.
680
[stderr] > Process 'command 'node'' finished with non-zero exit value 1
681
[stderr] * Try:
682
[stderr] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
683
[stderr] ==============================================================================
684
[stderr] 2: Task failed with an exception.
685
[stderr] -----------
686
[stderr] * What went wrong:
687
[stderr] Execution failed for task ':app:bundleReleaseJsAndAssets_SentryUpload_1'.
688
[stderr] > Process 'command '/build/workingdir/build/client/app/public/node_modules/@sentry/cli/bin/sentry-cli'' finished with non-zero exit value 1
689
[stderr] * Try:
690
[stderr] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
691
[stderr] ==============================================================================
692
[stderr] * Get more help at https://help.gradle.org
693
[stderr] BUILD FAILED in 1m 52s
694
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
695
Use '--warning-mode all' to show the individual deprecation warnings.
696
See https://docs.gradle.org/6.8/userguide/command_line_interface.html#sec:command_line_warnings
697
301 actionable tasks: 301 executed
698
Error: Gradle build failed with unknown error. Please see logs for the "Run gradlew" phase.

Theres 2 issues here, one is based with sentry (not at all sure why, but ive followed all the setup as per the docs). I’ve got the plugin and the hook setup inside multiple app.json files - its the same in each file:

...
   "hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "REDACTED",
            "project": "REDACTED",
            "authToken": "REDACTED",
            "setCommits": true
          }
        }
      ]
    },
    "extra": {
      ...
    },
    "sdkVersion": "42.0.0",
    "plugins": ["sentry-expo"]

I’ve also seen that in another thread that for android builds creating an index.js with the following content can help:

import registerRootComponent from 'expo/build/launch/registerRootComponent';

import App from './App';

registerRootComponent(App);

Any ideas where I should continue poking to figure out how to get around this would be much appreciated!

Discovered the issue - someone updated the metro.config.js to include a node_modules folder - removing it has at least allowed the build to continue so the issue has been isolated at least

1 Like

The build server runs expo prebuild which generates that index.js file, I believe, so you shouldn’t need to do it yourself unless you’re using the Bare workflow.

Ah good to know about the index.js only being required in bare!

Looks like the issues we’ve been facing are 100% down to a badly written metro.config.js - while we have been following the guide to overwrite the content in defaultConfig, looks like we had some config that appears to work fine using regular expo build:ios / expo build:android but not at all in EAS.

Cleaning up metro (following this has helped How to import files from outside of root directory with React Native Metro bundler | by Dushyant Bansal | Medium) has now produced an .aab and .ipa - so looks like that sentry issue was a knock on effect from this metro config issue!

1 Like