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

index.android.bundle.hbc.e6d69f: No such file or directory #1765

Closed
eliw00d opened this issue Sep 8, 2021 · 23 comments
Closed

index.android.bundle.hbc.e6d69f: No such file or directory #1765

eliw00d opened this issue Sep 8, 2021 · 23 comments

Comments

@eliw00d
Copy link

eliw00d commented Sep 8, 2021

Environment

How do you use Sentry?
Sentry SaaS (sentry.io)

Which SDK and version?

    "@sentry/react-native": "2.6.2",

Steps to Reproduce

Tried to upgrade my project from React Native 0.63.4 to 0.65.1 and enable hermes for Android.

I am using a monorepo and have the following in my build.gradle:

project.ext.react = [
    cliPath: "../../../node_modules/react-native/cli.js",
    composeSourceMapsPath: "../../../node_modules/react-native/scripts/compose-source-maps.js",
    enableHermes: true,  // clean and rebuild if changing
    entryFile: "index.js",
    hermesCommand: "../../../../../node_modules/hermes-engine/%OS-BIN%/hermesc",
]

apply from: "../../../../../node_modules/react-native/react.gradle"
apply from: "../../../../../node_modules/@sentry/react-native/sentry.gradle"

Here is my android/sentry.properties:

defaults.url=https://sentry.io/
defaults.org=myOrganization
defaults.project=myProject
cli.executable=../../../node_modules/@sentry/cli/bin/sentry-cli

Expected Result

Source maps would be handled like before, but with hermes enabled for Android.

Actual Result

I get the following error related to a missing index.android.bundle.hbc file:

[16:32:20]: ▸ ^~~~~~~~~~~~~~~~
[16:32:26]: ▸ Failed to open file /frontend/applications/myProject/android/app/build/generated/assets/react/dev/release/index.android.bundle.hbc.e6d69f: No such file or directory
[16:32:28]: ▸ DEBUG   2021-09-08 16:32:28.064290 -05:00 sentry-cli version: 1.66.0, platform: "darwin", architecture: "x86_64"
[16:32:28]: ▸ INFO    2021-09-08 16:32:28.065016 -05:00 sentry-cli was invoked with the following command line: "/node_modules/@sentry/cli/sentry-cli" "react-native" "gradle" "--bundle" "/frontend/applications/myProject/android/app/build/generated/assets/react/dev/release/index.android.bundle" "--sourcemap" "/frontend/applications/myProject/android/app/build/generated/sourcemaps/react/dev/release/index.android.bundle.map" "--release" "[REDACTED]" "--dist" "[REDACTED]"
[16:32:28]: ▸ INFO    2021-09-08 16:32:28.072137 -05:00 Issuing a command for Organization: myOrganization Project: myProject
[16:32:28]: ▸ Processing react-native sourcemaps for Sentry upload.
[16:32:28]: ▸ INFO    2021-09-08 16:32:28.072173 -05:00   bundle path: /frontend/applications/myProject/android/app/build/generated/assets/react/dev/release/index.android.bundle
[16:32:28]: ▸ INFO    2021-09-08 16:32:28.072184 -05:00   sourcemap path: /frontend/applications/myProject/android/app/build/generated/sourcemaps/react/dev/release/index.android.bundle.map
[16:32:28]: ▸ error: No such file or directory (os error 2)
[16:32:28]: ▸ DEBUG   2021-09-08 16:32:28.108294 -05:00 client close; no transport to shut down  (from sentry)
[16:32:28]: ▸ DEBUG   2021-09-08 16:32:28.108346 -05:00 skipping update nagger because session is not attended
[16:32:28]: ▸ FAILURE: Build completed with 2 failures.

If I disable hermes for Android, it builds without errors.

iOS works fine.

Since I am using a monorepo, is there something I am missing in terms of giving Sentry and/or React Native the paths they need to create the .hbc file?

@liamjones
Copy link
Contributor

We're not using Hermes currently but maybe this will still help? I don't recall exactly all the changes we made to get Sentry working in the monorepo but, from what I can relocate:

packages/apps/[app-name]/android/app/build.gradle:

project.ext.react = [
        enableHermes     : false,  // clean and rebuild if changing
        hermesCommand: "../../../../../node_modules/hermes-engine/%OS-BIN%/hermesc",
        composeSourceMapsPath: "../../../node_modules/react-native/scripts/compose-source-maps.js",
        entryFile: "packages/apps/[app-name]/index.js",
        extraPackagerArgs: (project.env.get('EXTRA_PACKAGER_ARGS') != null ? project.env.get('EXTRA_PACKAGER_ARGS').split(' ') : [])
]

apply from: "../../../../../node_modules/react-native/react.gradle"
apply from: "../../../../../node_modules/@sentry/react-native/sentry.gradle"

Note, changed entryFile and we're not changing the Sentry cli path there, we're instead doing it in sentry.properties (I think because that way it also applies to sentry-cli when it's run via Fastlane)...

packages/apps/[app-name]/android/sentry.properties and packages/apps/[app-name]/ios/sentry.properties:

defaults.url=...
defaults.org=...
defaults.project=...
auth.token=...
cli.executable=../../../node_modules/@sentry/cli/bin/sentry-cli

App's iOS 'Bundle React Native code and images' build stage script changed to:

export SENTRY_PROPERTIES=sentry.properties
export PROJECT_ROOT=$PWD/..
export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map --entry-file packages/apps/[app-name]/index.js"
export NODE_BINARY=node
../../../../node_modules/@sentry/cli/bin/sentry-cli react-native xcode ../../../../node_modules/react-native/scripts/react-native-xcode.sh

(Note extra --entry-file option in EXTRA_PACKAGER_ARGS)

App's iOS 'Upload Debug Symbols to Sentry' build stage script changed to:

export SENTRY_PROPERTIES=sentry.properties
../../../../node_modules/@sentry/cli/bin/sentry-cli upload-dsym

The number of ../'s in those code blocks will obviously vary depending on your monorepo layout.

If it's still not working for you after all those changes let me know what error you get and maybe I can find what I've missed including here.

@eliw00d
Copy link
Author

eliw00d commented Sep 9, 2021

Unfortunately, it still has the same error with the few things that were different between our setups added. It seems like it does not generate the .hbc file at all.

For me, entryFile is relative to my project directory, so changing it to frontend/applications/myProject/index.js errored with:

error The resource `/frontend/applications/myProject/frontend/applications/myProject/index.js` was not found.

@liamjones
Copy link
Contributor

For me, entryFile is relative to my project directory,

Ah, I think something we are doing differently then is the fact that we change our projectRoot in each app's metro.config.js to reference the top of the monorepo (so the entryFile is then relative to that).

I think we did this to get references to images in submodules working correctly? It may also have been TypeScript related. Can't recall tbh.

Note, if this difference helps you, we had to add a dynamic blacklist/exclusionList to ensure only the current app was 'visible' to metro since our monorepo contains multiple RN apps:

const path = require('path');
const blacklist = require('metro-config/src/defaults/blacklist');

function escapeRegExp(string) {
    return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

const currentAppDirectoryName = __dirname.split(path.sep).pop()
const filesInAllAppDirectoriesExceptTheCurrentOne = new RegExp(`packages\/apps\/(?!${escapeRegExp(currentAppDirectoryName)})[^\/]+\/.*`)

module.exports = {
    projectRoot: path.resolve(__dirname, '../../../'),
    resolver: {
        blacklistRE: blacklist([filesInAllAppDirectoriesExceptTheCurrentOne])
    },
    transformer: {
        getTransformOptions: async () => ({
            transform: {
                experimentalImportSupport: false,
                inlineRequires: false,
            },
        }),
    },
};

@eliw00d
Copy link
Author

eliw00d commented Sep 21, 2021

Unfortunately, not able to get this to work with above suggestions. Any other thoughts?

@liamjones
Copy link
Contributor

Sorry, I'm not that familiar with hermes specifics, we haven't switched over to it yet due to some other blocking dependencies.

Might be worth asking on the Sentry Community discord? https://discord.com/invite/sentry

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2021

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@eliw00d
Copy link
Author

eliw00d commented Nov 4, 2021

This is still an issue for us. Any thoughts?

@jennmueng
Copy link
Member

@eliw00d See step 2 here: https://docs.sentry.io/platforms/react-native/manual-setup/hermes/#compile-for-android maybe try switching out the hermesCommand to the correct one with OS-BIN filled out?

@eliw00d
Copy link
Author

eliw00d commented Nov 4, 2021

@jennmueng Here is some additional output if it helps:

* Where:
Script './node_modules/react-native/react.gradle' line: 182

* What went wrong:
Execution failed for task ':app:bundleDevReleaseJsAndAssets'.
> Process 'command '../../../../../node_modules/hermes-engine/osx-bin/hermesc'' finished with non-zero exit value 6

The CI machine I am running on is indeed a Mac so osx-bin is correctly being used. It had exit code 6 which seems to indicate it did run. I look at line 182 of node_modules/react-native/react.gradle and this is where it is failing:

                    exec {
                        if (targetName.toLowerCase().contains("release")) {
                            // Can't use ?: since that will also substitute valid empty lists
                            hermesFlags = config.hermesFlagsRelease
                            if (hermesFlags == null) hermesFlags = ["-O", "-output-source-map"]
                        } else {
                            hermesFlags = config.hermesFlagsDebug
                            if (hermesFlags == null) hermesFlags = []
                        }

                        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                            commandLine("cmd", "/c", getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags)
                        } else {
                            commandLine(getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags)
                        }
                    }

I do not have hermesFlagsRelease set and it is not a Windows machine, so it should end up doing:

"../../../../../node_modules/hermes-engine/osx-bin/hermesc -O -output-source-map -emit-binary -out",

which matches what you linked me. Any thoughts on why that exec would fail?

@eliw00d
Copy link
Author

eliw00d commented Nov 4, 2021

On further study of react.gradle, I see this just before the exec:

                    def hbcTempFile = file("${jsBundleFile}.hbc")

And the error I am getting is:

[16:32:26]: ▸ Failed to open file /frontend/applications/myProject/android/app/build/generated/assets/react/dev/release/index.android.bundle.hbc.e6d69f: No such file or directory

It seems to be appending a SHA to the end of the hbc. Could it be as simple as that? Where it should be trying to open it as index.android.bundle.hbc instead of index.android.bundle.hbc.e6d69f?

@marandaneto
Copy link
Contributor

does that happen only for monorepo? is it only with hermes or without it too?

@eliw00d
Copy link
Author

eliw00d commented Nov 5, 2021

does that happen only for monorepo? is it only with hermes or without it too?

It works fine with Hermes disabled. It only fails at the point where it creates the .hbc file.

@eliw00d
Copy link
Author

eliw00d commented Nov 5, 2021

As for only happening for monorepo, I would assume so since we have to specify the paths to our root node_modules. Normal repos would have their node_modules where react-native expects to find it.

@marandaneto
Copy link
Contributor

@jennmueng do you have any hint on this?

@jennmueng
Copy link
Member

@eliw00d Hmm I'm turning blank here, it could just be like you said where it's adding a hash at the end of the filename. Also, if you remove the sentry build script:

- apply from: "../../../../../node_modules/@sentry/react-native/sentry.gradle"

does the error still occur or is this coming from the react native build script?

@eliw00d
Copy link
Author

eliw00d commented Nov 12, 2021

@jennmueng I removed that line but still get the same error.

@jennmueng
Copy link
Member

@eliw00d Hmm this tells us that this issue isn't caused by Sentry's build script then, but an issue is coming from the React Native build script itself.

@marandaneto
Copy link
Contributor

can you provide a minimal reproducible example so we can double-check that it's not a sentry's issue? the standard setup with Hermes just works using the latest RN SDK Version

@marandaneto
Copy link
Contributor

Closing the issue as a part of large repository cleanup, due to it being inactive and/or outdated.
Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it.
Cheers!

@rafael-fecha
Copy link

any updates here ? I have the same issue with "react-native": "0.67.4" and "@sentry/react-native": "3.4.0".

No such file or directory (os error 2) on Processing react-native sourcemaps for Sentry upload

@eliw00d
Copy link
Author

eliw00d commented Apr 4, 2022

Yes, actually! I finally figured this out a few months ago. Basically, our git branch names look something like feat/TICKET/description and Jenkins did not like any of the / in the workspace path. So, we had to do something like:

customWorkspace "{workspace}/${env.BRANCH_NAME.replaceAll('%2F', '/')}"

in our Jenkinsfile to get around it.

@remberluyckx
Copy link

I had the same problem and was stuck on this for days. Then by seeing your problem it helped me find the solution, apparently the problem was that in my project rootfolder the folder name contains a space (%20) and that's why it adds this SHA-1 code or whatever as a file extension after android.index.bundle.hbc...
By removing the space the release build now succeeds.

@marqroldan
Copy link

I also encountered this problem only to find out it's because of the % that I had in my folder name

🫠

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

No branches or pull requests

7 participants