Closed florianbepunkt closed 2 years ago
Hey, you have to use realm by window.require
and not include it via normal import. The issue is when Realm is imported in standard way, any packager will try to pack it as a bundle. And it has to be native node module packaged in Electron app.
By using window.require
you make sure it won't get packed in the bundle together with the rest of JS code.
Additionally you can still import Realm from 'realm'
for TypeScript typings. We have simple realm.ts
file:
// @mh: Importing Realm here is only used by TypeScript for typing, webpack wont pick it as long as we don't return it as an object.
import Realm from 'realm';
// @mh: This trick is required for Node in Electron (window.require) and not to make renderer WebPack pack this package
// (if Realm is included in webpack it tries to pack React Native libs which breaks the functionality of Electron app)
// Server on main and server and realm worker all have implementations of window object with require function
const RealmWindow = window.require('realm') as typeof Realm;
export const realm = (): typeof Realm => {
return RealmWindow;
};
// eslint-disable-next-line import/no-default-export
export default realm();
@florianbepunkt Can you use the work-around as described above?
@kneth Sorry, we decided against realm and for an indexdb infrastructure. Apologies for not closing this.
How frequently does the bug occur?
All the time
Description
Using electron forge and realm, I get this error as soon as I use / import realm. The error is in react-native, but I don't understand why react-native is even installed, as I'm working on an electron app.
Output of
npm ls react-native
Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
No response
Version
10.8.0
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
Mac OSX 11.6 M1/Arm arc
Build environment
Which debugger for React Native: ..