DataDog / expo-datadog

Datadog SDK for Expo
Apache License 2.0
8 stars 5 forks source link

build failing due to main.jsbundle.map file in root directory instead of ios #13

Closed sam1463 closed 1 year ago

sam1463 commented 1 year ago

Describe what happened Caveat: I am not 100% sure if this is an issue with this library, or another part of my build, but wanted to start here. My expo build is failing on uploading the main.jsbundle.map file to datadog, because that file ends up existing in the root directory of my project, instead of the ios directory. If I manually move the file to the ios directory, the build succeeds. Or, by patching this package with patch-package, I can have this repo specify the SOURCEMAP_FILE to be in the ios directory, which "fixes" the issue.

Steps to reproduce the issue:

Describe what you expected:

Additional context

contents of my patch:

diff --git a/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js b/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js
index b739962..25a0eb3 100644
--- a/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js
+++ b/node_modules/expo-datadog/build/plugin/withIosSourcemaps/withIosSourcemaps.js
@@ -6,7 +6,7 @@
  */
 Object.defineProperty(exports, "__esModule", { value: true });
 const config_plugins_1 = require("@expo/config-plugins");
-const SOURCEMAP_FILE_COMMAND = "export SOURCEMAP_FILE=./main.jsbundle.map";
+const SOURCEMAP_FILE_COMMAND = "export SOURCEMAP_FILE=./ios/main.jsbundle.map";
 const DATADOG_XCODE_COMMAND = `yarn datadog-ci react-native xcode \`\\\"$NODE_BINARY\\\" --print \\\"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\\\"\``;
 const withIosSourcemaps = (config) => {
     return (0, config_plugins_1.withXcodeProject)(config, async (config) => {
diff --git a/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts b/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts
index 4202315..4200108 100644
--- a/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts
+++ b/node_modules/expo-datadog/src/plugin/withIosSourcemaps/withIosSourcemaps.ts
@@ -7,7 +7,7 @@
 import type { ConfigPlugin } from "@expo/config-plugins";
 import { withXcodeProject } from "@expo/config-plugins";

-const SOURCEMAP_FILE_COMMAND = "export SOURCEMAP_FILE=./main.jsbundle.map";
+const SOURCEMAP_FILE_COMMAND = "export SOURCEMAP_FILE=./ios/main.jsbundle.map";
 const DATADOG_XCODE_COMMAND = `yarn datadog-ci react-native xcode \`\\\"$NODE_BINARY\\\" --print \\\"require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'\\\"\``;

 const withIosSourcemaps: ConfigPlugin<void> = (config) => {
louiszawadzki commented 1 year ago

Hi @sam1463, thanks for reaching out!

Unfortunately we cannot reproduce the issue on our end.

To help use troubleshoot what could be causing the issue in your case, could you share the content of the following files (you can redact parts of them if they contain secrets or ids):

Thanks a lot!

dprgarner commented 1 year ago

I've seen a similar issue in my own project: the expo-datadog xcode script calls datadog-ci, and that script fails because it's looking for a bundlemap in the ./ios directory when it's actually been generated in the root of the project. I've been able to reproduce this by creating a brand new project from scratch with no other plugins except expo-datadog. The minimal example repo is viewable here - but I think you'll need to set up some certificates and mobileprovision etc. to run this, as the bug is only visible when running in a production profile.

However, this repo is slightly different from @sam1463 's set-up, as I'm having this issue in the most recent version of expo-datadog (49.0.0), and I'm running this in EAS locally. I wasn't able to fix this issue with the above patch on the env variable SOURCEMAP_FILE in withIosSourcemaps.js, though. I think this is because the datadog-ci script was looking for the bundle file in ./ios/ios/main.jsbundle.map.

I was able to fix the build in my repo and the example repo by applying the following patch to datadog-ci:

--- a/node_modules/@datadog/datadog-ci/dist/commands/react-native/xcode.js
+++ b/node_modules/@datadog/datadog-ci/dist/commands/react-native/xcode.js
@@ -175,7 +175,7 @@ class XCodeCommand extends clipanion_1.Command {
         };
         this.getSourcemapsLocation = () => {
             if (process.env.SOURCEMAP_FILE) {
-                return `${process.env.SOURCEMAP_FILE}`;
+                return path_1.join('..', `${process.env.SOURCEMAP_FILE}`);
             }
             if (process.env.EXTRA_PACKAGER_ARGS) {
                 const splitArguments = process.env.EXTRA_PACKAGER_ARGS.split(' ');

...but I'm not planning to open a PR on that repo with this change, heh. I think this is an issue with the way the relative paths are set in the calling expo-datadog script, rather than the datadog-ci or react-native-xcode scripts.

louiszawadzki commented 1 year ago

Hi @dprgarner, thanks a lot for providing an example reproducing the error!

I can reproduce it on my end, I am investigating on a fix for expo-datadog and will let you know once it is ready.

louiszawadzki commented 1 year ago

Hi @dprgarner @sam1463,

Thank you again for reporting this issue. I've tested it and it should have been fixed with version 49.0.1 of expo-datadog.

Feel free to reopen the issue if it is not fixed for you.

dprgarner commented 1 year ago

I've tried out the new package version in my project, and sourcemap uploading is working now. Thanks!