-
Notifications
You must be signed in to change notification settings - Fork 565
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
How to use realm on an electron app? #1060
Comments
Is this running with debugger attached? Can you share a simple prototype demonstrating this issue? |
Yeah, and this is the file structure of my project, and I use |
Does the error means that I need the module |
@DoubleWoodH Can you share this project or similar one so I can debug the issue. It seems all should be fine for your project but I suspect it may be related to something like the development environment setup etc. |
The first thing https://github.com/realm/realm-js/blob/master/lib/browser/index.js imports is from react-native, and it includes importing the debuggers from NativeModules which is not something you need for a non-rn app. |
@martsie indeed you are right. It seems we might be using this file in non RN context. I will investigate more and will update this issue. |
@DoubleWoodH
No it probably means we have a bug in the code. React Native should not be required in your scenario |
@DoubleWoodH Same problem here. I guess it was because realm's For now, you can require realm in the html as a global variable like this: <script>
var Realm = require('realm')
</script> Note: This method doesn't work on webpack-dev-server, you can track this issue on webpack/webpack-dev-server#812. |
I found that I got this error when using Realm with webpack and bundling for the node target. |
#928 (comment) claims that Electron can work with Realm |
Still getting Any updates? |
@risabhkumar-cc are you using WebPack? Or any other bundler? Do you have some code or details on your setup that you can share? |
We do not support Electron. Realm Studio is an Electron app, and you are welcome to see how we are using Realm JS and Electron together. |
@kneth if you can add it in the readme or write a small blog on How to use realm with an Electron then It'll be a great help for the community. |
I see there's an incompatibility with webpack which I need to use it in my project in order to use hot reload functionality. |
A quick workaround in webpack: |
i tried to modify the webpack.config.dev.js in react-scripts but could not get this work. Still the same. How can i exclude realm from webpack config of react-scripts module ? |
this leads to |
Same here. |
Bumping this. Have tried a few of the suggestions here with no success. Has anyone successfully resolved: |
@bentron2000 It looks like you are getting the wrong context somehow (https://github.com/realm/realm-js/blob/master/lib/index.js#L111). Are you by any chance debugging it inside VSCode (https://github.com/realm/realm-js/blob/master/lib/index.js#L31)? At least, it could explain it 😄 |
Thanks for your quick response @kneth :) I think I am getting the wrong context - but I am not sure what config changes would be required to get the right one. I have built an electron app based on create-react-app and I'm simply using I reviewed https://github.com/realm/realm-js/blob/master/lib/index.js#L31 and logged out the process object - it doesn't fit with what realm expects here. (I'm not using vsdebugger) I assume this has something to do with my build process but I'm quite stuck on how to correct it. Many of the examples I can find seem to import realm and work with it directly - including the large-virtualized-datagrid example on the realm github. Thanks again for any help B |
@bentron2000 The best example I know is https://github.com/realm/realm-studio/ |
@kneth Thanks again for your prompt response. As it turns out - my attempt to use create-react-app with electron and realm was a fools errand. For anyone else wishing to use electron/react/typescript/realm - the simplest way to get started is to use electron-forge and the react/typescript template, then add the realm npm package / import realm. Couldn't be simpler really.
Hope this helps someone :) B |
The reason you're seeing this issue is because create react app uses webpack internally. When bundling your app it follows all calls to require and tries to recursively include those in its bundle. Realm JS is not build to support being bundling and to prevent it from being bundled Realm Studio uses the webpack-node-externals package to exclude Realm (and all other node_modules) from the bundle https://github.com/realm/realm-studio/blob/master/configs/webpack.base.js#L17. I'm glad you found a way around the issue by using |
What a hell? Still no solution for this?! =( |
@kraenhansen |
5 days of research with no results, and this works for me. using electron-forge set in webpack.main.config
|
Here is my webpack.main.config and it still doesn't work. Is it correct? module.exports = {
|
I want to use
realm
on anelectron
app with Node 6, and I used the code below but it doesn't work and the error imformation is above.The text was updated successfully, but these errors were encountered: