Closed IronTony closed 2 years ago
Thanks for creating an issue.
In the hermes
branch, we rely on the bundler (or whatever resolves package main fields) look for the "react-native" main field. We think this is reasonable, since it is default behaviour of the Metro server when invoked via the React Native CLI.
It seems to me that the babel-plugin-module-resolver package resolves main fields like Node.js (primarily looking for a "main" field) as it uses the resolve
package to perform the resolution. Neither seem to export an easy way to configure the main field, so I'd expect these to be packages primarily written for the Node.js community. The resolve
package does have an option (packageFilter
) to transform the package.json before it's resolved, but that isn't used or exposed through the babel plugin. Perhaps one could implement a variant of the resolvePath function which would work reliably in a React Native project.
The ideal solution to me, would be that the module-resolver
Babel plugin exposed a way to configure "main fields" to look for. As a potential solution for this specific issue, I see that we might be able to drop a lib/index.native.js
which simply re-exports our lib/react-native/index.js
effectively implementing the "native-specific extension": https://reactnative.dev/docs/platform-specific-code#native-specific-extensions-ie-sharing-code-with-nodejs-and-web.
I'll get a release out with this fix and π€ that's enough.
Hi @kraenhansen, thank you so much for the detailed explanation, really appreciated. I will wait for the fix release and I hope that it will be enough.
Moreover I did some other tests, and I found a strange thing.
Here is an extract of my App.tsx
<Suspense fallback={<SCLSplashscreen />}>
<ApolloProvider client={client}>
<RealmProvider>
<View>
<Text>TEST</Text>
</View>
</RealmProvider>
</ApolloProvider>
</Suspence>
And this is my Realm provider:
import Loader from '@components/Loader';
import React, { createRef, useEffect, useState } from 'react';
import Realm from 'realm';
import { realmDBContext } from './context';
import User from './models/user';
// Open a local realm file with the schema(s) that are a part of this realm.
const config = {
schema: [User.schema],
};
const realmRef = createRef<Realm>();
const openRealm = async () => {
const realm = await Realm.open(config); // <<<< BROKE THE COMPILATION AT RUNTIME!!!!
realmRef.current = realm;
/// FlipperDatabasesPlugin - START
if (__DEV__) {
// Import connectDatabases function and required DBDrivers
const { connectDatabases, RealmDB } = require('react-native-flipper-databases');
connectDatabases([
new RealmDB('Realm', realm), // Pass in realm reference
]);
}
/// FlipperDatabasesPlugin - END
};
export const RealmProvider: React.FC = ({ children }) => {
const [isReady, setReady] = useState(false);
useEffect(() => {
openRealm().then(() => {
setReady(!realmRef?.current?.isClosed);
});
// Return a cleanup callback to close the realm to prevent memory leaks
return () => {
const realm = realmRef.current;
realm?.close();
realmRef.current = null;
setReady(!realm?.isClosed);
};
}, []);
if (!isReady || !realmRef.current) {
return <Loader fullPage />;
}
return <realmDBContext.Provider value={realmRef}>{children}</realmDBContext.Provider>;
};
Hi @kraenhansen
I tried to install the hermes branch (yarn add realm@hermes
), but it seems to that the version is not the last one with your commits, in fact I have always the same error during runtime
@IronTony I'm awaiting an "upstream" release on the master channel before I can get this out. I hope to get it released in the start of the coming week. Sorry for the delay here.
@kraenhansen no problem. I thought I was doing something wrong. Thank you
@IronTony we have a new release out with a fix for this π€ Please try out v10.20.0-beta.4 and reopen if the issue persists.
Thank you. I will try tomorrow and for the best!!! π€πΌπ€πΌπ€πΌ
How frequently does the bug occur?
All the time
Description
After iOS and Android compilation, when the server starts to load the application, I receive this error:
I am using a custom RN boilerplate. If I add the realm package (10.20.0-beta.3) to the downloaded boilerplate and try to compile, the compilation will work and I do not receive the error above.
Instead when I use the same package in the same boilerplate but with also other packages installed (reanimated 2.5.0, apollo client 3.5.10, and so on...) I receive the error during the application load in the server (as the error above)
This is my
metro.config.js
These are some packages in my
package.json
:Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
No response
Version
10.20.0-beta.3
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
iOS and Android
Build environment
No response
Cocoapods version
No response