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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/many-fishes-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@powersync/react-native': patch
---

Fixed issue where CRUD uploads could fail with the error

```
Exception: require(_dependencyMap[11], "rea(...)/BlobManager").createFromOptions is not a function (it is undefined)
```
9 changes: 6 additions & 3 deletions packages/react-native/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import inject from '@rollup/plugin-inject';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import path from 'path';
import { fileURLToPath } from 'url';
import terser from '@rollup/plugin-terser';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -34,7 +34,7 @@ export default (commandLineArgs) => {
}),
json(),
nodeResolve({
preferBuiltins: false,
preferBuiltins: false
}),
commonjs({}),
inject({
Expand All @@ -48,6 +48,10 @@ export default (commandLineArgs) => {
alias({
entries: [
{ find: 'bson', replacement: path.resolve(__dirname, '../../node_modules/bson/lib/bson.rn.cjs') },
{
find: 'react-native/Libraries/Blob/BlobManager',
replacement: path.resolve(__dirname, './vendor/BlobManager.js')
}
]
}),
terser()
Expand All @@ -59,7 +63,6 @@ export default (commandLineArgs) => {
'node-fetch',
'js-logger',
'react-native',
'react-native/Libraries/Blob/BlobManager',
'react'
]
};
Expand Down
27 changes: 27 additions & 0 deletions packages/react-native/vendor/BlobManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The current Rollup configuration targets a CommonJs output.
* This translates import statements to require statements.
* React native recently shifted to ESM exports.
* https://github.com/facebook/react-native/pull/48761/files
* This causes requiring this module to return an object
* of the form:
* ```javascript
* {
* _esModule: true,
* default: BlobManager
* }
* ```
* This wrapper provides a small shim to conditionally return the default export of the module.
*/
const BlobManager = require('react-native/Libraries/Blob/BlobManager');
const interop = (mod) => (mod && mod.__esModule ? mod.default : mod);

/**
* Using an ESM export here is important. Rollup compiles this to
* ```javascript
* const BlobManager = require('react-native/Libraries/Blob/BlobManager');
* const interop = (mod) => (mod && mod.__esModule ? mod.default : mod);
* var BlobManager$1 = interop(BlobManager);
* ```
*/
export default interop(BlobManager);