How do I generate/download sourcemaps using eas build?

How do I generate/download sourcemaps using eas build? I see bugnsag and sentry projects both manually modify the build via plugins. Is this the only way?

Examples:

sourcemaps are generated by making a request to metro. sentry and bugsnag both add this to the build phases because this is the natural place to put it so it runs on every build. if you have some other need, you could start a metro server separately and do this. it’s best when asking these questions to explain the use case though

1 Like

I’m confused. How do I make a request to metro during the EAS build process?

The use case is that I have EAS build running successfully, but I want to gain access to the source maps generated during the build that EAS is creating. If no source maps are being created, I want to be able to create them.

I’m sorry I was not clear. I’m not quite sure how to phrase the question appropriately.

1 Like

we don’t create source maps by default because that would be wasteful to do on every build, where they are not used.

you can look at how those other libraries create sourcemaps, or you can find any guide that explains how to get sourcemaps for react-native and follow that. it’s no different in this context. you would just have to call that code from within an eas build lifecycle hook: Build lifecycle hooks - Expo Documentation

it might also be useful to see: npx expo export --dump-sourcemap

notice that in dist/bundles contains sourcemaps. the only danger here is that this may not align with exactly how the bundle is generated when a build is run.

once you have the sourcemaps, what are you going to do with them? upload them to a service like sentry or bugsnag? it’s not clear to me why you wouldn’t use their integrations

Re-reading your comments, it seems that generating the sourcemaps is not currently a feature built into the EAS build process and to build access the sourcemaps we have two options:

  1. A build plugin similar to expo-sentry or bugsnag
  2. Using the build lifecycle hooks

Is that accurate?

Thank you so much for your time and help @brents !

Ugh, my earlier response to your questions is now missing. Comcast has been working on my home internet lines and it’s been spotty.

it might also be useful to see: npx expo export --dump-sourcemap

as you say, this didn’t align correctly to the EAS build.

once you have the sourcemaps, what are you going to do with them? upload them to a service like sentry or bugsnag? it’s not clear to me why you wouldn’t use their integrations

Yes, both for access internally and Sentry. Just Sentry would work and we could download the sourcemaps from Sentry, however we do not wish to use expo-sentry. We have Sentry enabled without expo-sentry, but we are missing the sourcemaps functionality.

i’d approach it like this:

  • figure out how to dump sourcemaps during a in any react-native project, independent of EAS Build (it seems that you could look to the plugins from sentry/bugsnag to get some insight). for example, i believe you could just run npx react-native start and then make a request to the metro server with the correct path/params to download the sourcemaps.
  • configure your project to do that on EAS Build. that could be with a plugin or a hook. you can either upload the sourcemap file somewhere from within this hook, or add it to the artifacts that EAS Build will provide at the end of the build process (note: we are about to split the property artifactPath into two distinct values: [ENG-3865][docs] update docs on EAS Build artifacts by dsokal · Pull Request #18921 · expo/expo · GitHub)
1 Like

Thanks @brents !

We have sourcemaps functional and working on non-expo/eas projects.

I eagerly await that pr being merged so that we can access additional artifacts.

Thank you for finding that pr!!

you can already do this with the artifactPath option: Build schema for eas.json - Expo Documentation

but we are moving away from this to the fields mentioned above in order to clearly separate application and other artifacts

Fantastic!

Unfortunately, it does not appear that eas-build-on-success runs successfully locally. It is possible I have misconfigured things.

Snippet from package.json

"scripts": {
    "eas-build-on-success": "echo 123",

Command

npx eas build --profile=production -p ios --local --clear-cach

I tried several permutations of echo commands and I do see the following, but no output

[READ_PACKAGE_JSON] {
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "eas-build-on-success": "echo 123",
    "start": "expo start",
[RUN_FASTLANE]
[RUN_FASTLANE] Successfully exported and compressed dSYM file
[RUN_FASTLANE] Successfully exported and signed the ipa file:
[RUN_FASTLANE] /private/var/folders/z8/ctrh1ssn4td1jflmz8q1jfn40000gn/T/eas-build-local-nodejs/fc9064cd-6bc4-44e2-9853-933da68aa187/build/ios/build/foo.ipa
[CLEAN_UP_CREDENTIALS] Destroying keychain - /var/folders/z8/ctrh1ssn4td1jflmz8q1jfn40000gn/T/turtle-v2-8b364d51-13b1-40aa-bebb-3b17671e0467.keychain
[CLEAN_UP_CREDENTIALS] Removing provisioning profile
[UPLOAD_ARTIFACTS] Build artifacts: /var/folders/z8/ctrh1ssn4td1jflmz8q1jfn40000gn/T/eas-build-local-nodejs/fc9064cd-6bc4-44e2-9853-933da68aa187/build/ios/build/foo.ipa
[PREPARE_ARTIFACTS] Archiving artifacts

Re-read iOS build process - Expo Documentation and I can confirm I do not see the output “123” anywhere after RUN_FASTLANE

For giggles I tried

EXTRA_PACKAGER_ARGS="--sourcemap-output ./main.jsbundle.map" npx eas build --profile=production -p ios --local --clear-cache

but it doesn’t look like that ENV var gets passed all the way down, or I’m looking in the wrong spaces. At this point I’m going to assume the safest and best path forward is via a plugin.

You’d have to define the environment variable in an “env” section in eas.json for it to be available on the build servers.

EDIT: Never mind, I just scrolled right and noticed the --local in there.

npx eas does not support the build hooks.

When I installed eas-cli and ran that the hooks worked.

I must have mis-read the documentation again :frowning: I thought we were supposed to be using npx eas where possible. Sorry!

Indeed I did!!!

Running builds on your own infrastructure - Expo Documentation explicitly mentions eas not npx eas :frowning:

If you have eas-cli installed as a dependency of your app, uninstall it. It should only be installed globally.

aha, I have it listed in devDependencies. I also have the same for expo-cli. I will remove both. Thank you!

1 Like

Fabulous! The hooks work as expected locally now!

I can use the eas-build-post-install to run the sentry-wizard to modify the Xcode build and gradle config on the fly and avoid writing a plugin.

Now I need to update the artifactPath and that should expose the sourcemaps for local use.

Thank you @brents and @wodin!

1 Like