question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] 'mainjs.bundle.map' not found when composing sourcemaps with Hermes.

See original GitHub issue

Description

When building the app for iOS, if you set the env var SOURCEMAP_FILE when bundling it generates an error when composing sourcemaps.

As I understand the culprit appears to be this parts of the react-native-xcode.sh script:

If SOURCEMAP_FILE is not empty, then EMIT_SOURCEMAP.

EMIT_SOURCEMAP=
if [[ ! -z “$SOURCEMAP_FILE” ]]; then
  EMIT_SOURCEMAP=true
fi

Here it seems that if EMIT_SOURCEMAP is true, it generates the sourcemap in the bundle script

PACKAGER_SOURCEMAP_FILE=
if [[ $EMIT_SOURCEMAP == true ]]; then
  if [[ $USE_HERMES == true ]]; then
    PACKAGER_SOURCEMAP_FILE=“$CONFIGURATION_BUILD_DIR/$(basename $SOURCEMAP_FILE)”
  else
    PACKAGER_SOURCEMAP_FILE=“$SOURCEMAP_FILE”
  fi
  EXTRA_ARGS=“$EXTRA_ARGS --sourcemap-output $PACKAGER_SOURCEMAP_FILE”
fi

if [[ $USE_HERMES != true ]]; then
  cp “$BUNDLE_FILE” “$DEST/”
  BUNDLE_FILE=“$DEST/main.jsbundle”
else
  EXTRA_COMPILER_ARGS=
  if [[ $DEV == true ]]; then
    EXTRA_COMPILER_ARGS=-Og
  else
    EXTRA_COMPILER_ARGS=-O
  fi

Here it where confuses me, I don’t know (and couldn’t find them) which flags and how they work for the Hermes compiler. Here the flag “-output-source-map” is setted but I don’t actually know if it does something.

  if [[ $EMIT_SOURCEMAP == true ]]; then
    EXTRA_COMPILER_ARGS=“$EXTRA_COMPILER_ARGS -output-source-map”
  fi
  “$HERMES_CLI_PATH” -emit-binary $EXTRA_COMPILER_ARGS -out “$DEST/main.jsbundle” “$BUNDLE_FILE”

And here is kind of weird too. It seems that a “mainjs.bundle.map” should exist next to “main.jsbundle” but it doesn’t, hence causing the error.

if [[ $EMIT_SOURCEMAP == true ]]; then
    HBC_SOURCEMAP_FILE=“$BUNDLE_FILE.map”
    “$NODE_BINARY” “$COMPOSE_SOURCEMAP_PATH” “$PACKAGER_SOURCEMAP_FILE” “$HBC_SOURCEMAP_FILE” -o “$SOURCEMAP_FILE”
  fi
  BUNDLE_FILE=“$DEST/main.jsbundle”
fi

This is the build phase:

export NODE_BINARY=node
export SOURCEMAP_FILE=“${PROJECT_DIR}/../sourcemap.ios.js”
export PROJECT_ROOT=“${PROJECT_DIR}/../”
../../../node_modules/react-native/scripts/react-native-xcode.sh index.js

This is the XCode report: bundle-xcode-report.txt

The error is:

+ [[ true == true ]]
+ HBC_SOURCEMAP_FILE=/Users/path/to/DerivedData/intermediates/BuildProductsPath/Release.development-iphoneos/main.jsbundle.map
+ node /Users/user/Workspace/UtilityGO-Office-Mobile/node_modules/react-native/scripts/compose-source-maps.js /Users/path/to/DerivedData/intermediates/BuildProductsPath/Release.development-iphoneos/sourcemap.ios.js /Users/path/to/DerivedData/intermediates/BuildProductsPath/Release.development-iphoneos/main.jsbundle.map -o /Users/path/to/ios/workspace/../sourcemap.ios.js
internal/fs/utils.js:314
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/Users/path/to/DerivedData/intermediates/BuildProductsPath/Release.development-iphoneos/main.jsbundle.map'
    at Object.openSync (fs.js:498:3)
    at Object.readFileSync (fs.js:394:35)
    at Object.<anonymous> (/Users/user/Workspace/UtilityGO-Office-Mobile/node_modules/react-native/scripts/compose-source-maps.js:35:8)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/path/to/DerivedData/intermediates/BuildProductsPath/Release.development-iphoneos/main.jsbundle.map'
}

I don’t know if I’m misunderstanding how SOURCEMAP_FILE works, if doing something wrong or is actually a bug.

It would be really great if I can get some help with this!

Thank you!

Version

0.65.1

Output of react-native info

System: OS: macOS 11.6 CPU: (4) x64 Intel® Core™ i5-5257U CPU @ 2.70GHz Memory: 1.15 GB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.3 - /var/folders/16/pt1bzhnj0t723m8dhdfjv8c80000gn/T/yarn–1635445381302-0.42400434651762153/node Yarn: 1.22.10 - /var/folders/16/pt1bzhnj0t723m8dhdfjv8c80000gn/T/yarn–1635445381302-0.42400434651762153/yarn npm: 7.24.0 - ~/Workspace/UtilityGO-Office-Mobile/node_modules/.bin/npm Watchman: 2021.06.07.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.2 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7583922 Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild Languages: Java: javac 17 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: Not Found react-native: Not Found react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Add SOURCEMAP_FILE env var when bundling, like this:

export NODE_BINARY=node
export SOURCEMAP_FILE=“${PROJECT_DIR}/../sourcemap.ios.js”
export PROJECT_ROOT=“${PROJECT_DIR}/../”
../../../node_modules/react-native/scripts/react-native-xcode.sh index.js

Snack, code example, screenshot, or link to a repository

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kidrocacommented, Jun 30, 2022

I’ve stumbled on that bug too - specifying a SOURCEMAP_FILE path in xCode’s build phase would fail if you have hermes enabled, because of a filename mismatch

It’s because of this part here: https://github.com/facebook/react-native/blob/4ea38e16bf533955557057656cba5346d2372acd/scripts/react-native-xcode.sh#L169-L174

Since we set -out "$DEST/main.jsbundle" the (hbc) source maps would be output next to main.jsbundle in $DEST

The line here needs to change

HBC_SOURCEMAP_FILE="$BUNDLE_FILE.map" 

$BUNDLE_FILE refers to the packager bundle file, which is still outside of $DEST hence the error

Error: ENOENT: no such file or directory, open ‘/Users/path/to/DerivedData/intermediates/BuildProductsPath/Release.development-iphoneos/main.jsbundle.map’

The HBC_SOURCEMAP_FILE is inside $DEST

Suggested change:

- HBC_SOURCEMAP_FILE="$BUNDLE_FILE.map"
+ HBC_SOURCEMAP_FILE="$DEST/main.jsbundle.map" 
0reactions
taltruicommented, Apr 28, 2022

Hi! Does anyone knows something about this?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does react native include sourcemaps in the release bundle?
I'm pretty sure they're not included but I can't seem to find a definitive answer about whether they are. I can see in...
Read more >
Source code was not found for /main.jsbundle - #sentry
Hi there! We are having an issue with artefacts using self-hosted sentry 8.7.0 We user raven-js to track error in a react-native app, ......
Read more >
IPH - River Thames Conditions - Environment Agency - GOV.UK
Comment ouvrir son iphone 3gs, Ffxiii-2 chichu godly build, ... Uroki na piano, Schubert op 90 no 3 impromptu, Naswiz login, Hoggs falls...
Read more >
Untitled
Hialeah casino poker, Daily star chelseafc, Default password iphone 4 voicemail, ... Android aio flasher device not found, Robot building games for pc, ......
Read more >
Untitled
Rey is bae meme, Blendon woods park map, Hasil akhir persidafon vs barito putera, ... Bitlocker recovery key not found, Jiu shi xian...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found