Skip to content

Commit 84cdd9d

Browse files
[React Native] Fix BlobManager import (#595)
1 parent f5abaf1 commit 84cdd9d

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

.changeset/many-fishes-camp.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@powersync/react-native': patch
3+
---
4+
5+
Fixed issue where CRUD uploads could fail with the error
6+
7+
```
8+
Exception: require(_dependencyMap[11], "rea(...)/BlobManager").createFromOptions is not a function (it is undefined)
9+
```

packages/react-native/rollup.config.mjs

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import inject from '@rollup/plugin-inject';
44
import json from '@rollup/plugin-json';
55
import nodeResolve from '@rollup/plugin-node-resolve';
66
import replace from '@rollup/plugin-replace';
7+
import terser from '@rollup/plugin-terser';
78
import path from 'path';
89
import { fileURLToPath } from 'url';
9-
import terser from '@rollup/plugin-terser';
1010

1111
const __filename = fileURLToPath(import.meta.url);
1212
const __dirname = path.dirname(__filename);
@@ -34,7 +34,7 @@ export default (commandLineArgs) => {
3434
}),
3535
json(),
3636
nodeResolve({
37-
preferBuiltins: false,
37+
preferBuiltins: false
3838
}),
3939
commonjs({}),
4040
inject({
@@ -48,6 +48,10 @@ export default (commandLineArgs) => {
4848
alias({
4949
entries: [
5050
{ find: 'bson', replacement: path.resolve(__dirname, '../../node_modules/bson/lib/bson.rn.cjs') },
51+
{
52+
find: 'react-native/Libraries/Blob/BlobManager',
53+
replacement: path.resolve(__dirname, './vendor/BlobManager.js')
54+
}
5155
]
5256
}),
5357
terser()
@@ -59,7 +63,6 @@ export default (commandLineArgs) => {
5963
'node-fetch',
6064
'js-logger',
6165
'react-native',
62-
'react-native/Libraries/Blob/BlobManager',
6366
'react'
6467
]
6568
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* The current Rollup configuration targets a CommonJs output.
3+
* This translates import statements to require statements.
4+
* React native recently shifted to ESM exports.
5+
* https://github.com/facebook/react-native/pull/48761/files
6+
* This causes requiring this module to return an object
7+
* of the form:
8+
* ```javascript
9+
* {
10+
* _esModule: true,
11+
* default: BlobManager
12+
* }
13+
* ```
14+
* This wrapper provides a small shim to conditionally return the default export of the module.
15+
*/
16+
const BlobManager = require('react-native/Libraries/Blob/BlobManager');
17+
const interop = (mod) => (mod && mod.__esModule ? mod.default : mod);
18+
19+
/**
20+
* Using an ESM export here is important. Rollup compiles this to
21+
* ```javascript
22+
* const BlobManager = require('react-native/Libraries/Blob/BlobManager');
23+
* const interop = (mod) => (mod && mod.__esModule ? mod.default : mod);
24+
* var BlobManager$1 = interop(BlobManager);
25+
* ```
26+
*/
27+
export default interop(BlobManager);

0 commit comments

Comments
 (0)