Skip to content

fix: await updatePodfile to prevent race condition during prebuild#254

Open
tarikfp wants to merge 1 commit intoOneSignal:mainfrom
tarikfp:fix/podfile-race-condition
Open

fix: await updatePodfile to prevent race condition during prebuild#254
tarikfp wants to merge 1 commit intoOneSignal:mainfrom
tarikfp:fix/podfile-race-condition

Conversation

@tarikfp
Copy link

@tarikfp tarikfp commented Jan 22, 2026

What's happening

When running npx expo prebuild, the build randomly fails with:

❌ 'OneSignalFramework/OneSignalFramework.h' file not found

or

❌ 'OneSignalExtension/OneSignalExtension.h' file not found

The OneSignalNotificationServiceExtension target never gets added to the Podfile before pod install runs.

Related issues: #231

Why it happens

Two things are causing this:

1. The updatePodfile call isn't awaited

In withOneSignalIos.ts:

// not awaiting in order to not block main thread
const iosRoot = path.join(config.modRequest.projectRoot, "ios")
updatePodfile(iosRoot).catch(err => { OneSignalLog.error(err) });

The comment says it's intentional, but this causes prebuild to move on to pod install before the Podfile is updated.

2. The file write itself is async

In updatePodfile.ts:

fs.appendFile(`${iosPath}/Podfile`, NSE_PODFILE_SNIPPET, (err) => { ... });

Even if we awaited the function, fs.appendFile with a callback returns immediately.

The fix

withOneSignalIos.ts

- // not awaiting in order to not block main thread
- updatePodfile(iosRoot).catch(err => { OneSignalLog.error(err) });
+ await updatePodfile(iosRoot);

updatePodfile.ts

- fs.appendFile(`${iosPath}/Podfile`, NSE_PODFILE_SNIPPET, (err) => {
-     if (err) {
-         OneSignalLog.error("Error writing to Podfile");
-     }
- });
+ try {
+     fs.appendFileSync(`${iosPath}/Podfile`, NSE_PODFILE_SNIPPET);
+     OneSignalLog.log("OneSignalNotificationServiceExtension target added to Podfile.");
+ } catch (err) {
+     OneSignalLog.error("Error writing to Podfile: " + err);
+ }

Tested with

  • onesignal-expo-plugin: 2.0.3
  • expo: 53.0.0
  • react-native: 0.79.6
  • react-native-onesignal: 5.2.16
  • Node.js: 22.19.0
  • Xcode: 26.0.1

Before/After

Before:

$ npx expo prebuild --clean
$ grep "OneSignalNotificationServiceExtension" ios/Podfile
# nothing

$ npx expo run:ios
❌ 'OneSignalExtension/OneSignalExtension.h' file not found

After:

$ npx expo prebuild --clean
onesignal-expo-plugin: OneSignalNotificationServiceExtension target added to Podfile.

$ grep "OneSignalNotificationServiceExtension" ios/Podfile
target 'OneSignalNotificationServiceExtension' do

$ npx expo run:ios
✅ Build succeeds

The updatePodfile function was being called without await, causing the
Expo prebuild process to continue to pod install before the Podfile
was updated with the OneSignalNotificationServiceExtension target.

This resulted in build failures with errors like:
- 'OneSignalFramework/OneSignalFramework.h' file not found
- 'OneSignalExtension/OneSignalExtension.h' file not found

Changes:
- Add await to updatePodfile call in withOneSignalIos.ts
- Use fs.appendFileSync instead of fs.appendFile in updatePodfile.ts
@tarikfp tarikfp marked this pull request as ready for review January 22, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant