Skip to content

[React Native] Fix BlobManager import #595

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

Merged
merged 8 commits into from
May 13, 2025
Merged

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented May 12, 2025

Overview

Users have recently reported errors of the form

Exception: require(_dependencyMap[11], "rea(...)/BlobManager").createFromOptions is not a function (it is undefined)

when CRUD uploads were completed.

The BlobManager is used by the react-native-fetch-api package to parse HTTP request responses. The error here seems to be caused by the SDK making a call to the PowerSync service's write-checkpoint2.json endpoint after completing CRUD uploads.

Users confirmed that using the Expo implementation for fetch resolves the issue. See this POC #591.

Expo's fetch implementation is great, but it is included directly in the expo NPM package. Bare React Native users unfortunately do not have the option of using this fix. Conditional require/import statements are also not handled very well in Metro currently. Attempting to conditionally require expo/fetch can print an error message to the console for non Expo users.

The true root cause of this issue seems to be due to the React Native package gradually shifting to ESM exports. The BlobManager was recently converted to an ESM export https://github.com/facebook/react-native/pull/48761/files. Our Rollup config targets a CommonJS output which converts the import in react-native-fetch-api to a require statement. In some project environments, the require can resolve to an object of the form:

{
    _esModule: true,
    default: BlobManager
}

While we expect BlobManager to directly be returned. Our code then tries to access createFromOptions on the result, but this is undefined due to the ES module wrapper structure.

The fix here is to vendor a small wrapper for BlobManager which checks the result of requiring the BlobManager.

Testing

This was tested in a bare React Native App and in the Expo Supabase demo.

Copy link

changeset-bot bot commented May 12, 2025

🦋 Changeset detected

Latest commit: 76d5b61

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/react-native Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stevensJourney stevensJourney requested a review from Chriztiaan May 12, 2025 11:22
@stevensJourney stevensJourney marked this pull request as ready for review May 13, 2025 07:00
@stevensJourney stevensJourney merged commit 84cdd9d into main May 13, 2025
6 checks passed
@stevensJourney stevensJourney deleted the react-native-blob branch May 13, 2025 07:00
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.

2 participants