Closed blyshchykroman5 closed 3 years ago
Please share a bit more about your setup. Without it it's super difficult to help.
Are you for example using a bundler like webpack and have you tried externalizing your node modules from the bundle as I suggested in https://github.com/realm/realm-js/issues/1060#issuecomment-322767435?
I've run into this issue as well using electron, webpack, and realm, and following your suggestion to use webpack-node-externals allowed me to run the app. However, now the node modules obviously aren't there when attempting to build a distributable. @kraenhansen do you have suggestions for packaging the app?
Also came across this mess today, working with mongoDB technologies it a pain. Can't find a solution, and it seems like I might need to mess around with unnecessary packages.
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
Hi, Tony
On Mon, Sep 13, 2021 at 1:35 AM no-response[bot] @.***> wrote:
Closed #3927 https://github.com/realm/realm-js/issues/3927.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/realm/realm-js/issues/3927#event-5291310955, or unsubscribe https://github.com/notifications/unsubscribe-auth/AU47E44VZFMJ64ZUEYZMHUTUBWZV5ANCNFSM5C6PHDHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
@kraenhansen do you have suggestions for packaging the app?
@tsmarin since there are multiple ways to package the app, please create another issue with details on the tools you're using and any relevant errors that you might be seeing in the process.
I'll close this issue, since I didn't get a response from the original reporter. @blyshchykroman5 reopen this issue if you're still experiencing this, answering my questions above ☝️
For anyone else experiencing difficulties requiring realm
, please feel free to open your own issue with details on how to reproduce and we'll be sure to take a look to help you resolve this.
I am having the same issue with an Angular web app. Maybe MongoDB Realm should ditch the legacy port and rewrite your SDK's using modern module patterns for javascript apps? Why does a javascript (node) app try to load a React Native lib? Are you assuming that ALL node.js code is for React Native apps? Your modules should support some form of tree-shaking so that dependencies that are not needed can be discarded, or build and SDK specifically for React Native apps?
./node_modules/realm/lib/utils.js:149:12-35 - Warning: Module not found: Error: Can't resolve 'react-native'
I just want to query MongoDB Atlas database from Node and JS browser apps. This has turned out to be an epic failure.
Hey @jbeckton, sorry to hear you are having issues here. Just to confirm, are you trying to build an Electron app or are you building a web app?
If it's an Electron app, were you able to try the instructions for externalizing node_modules here (assuming you are using Webpack, if not your bundler may have an equivalent)?
If it's a web app, you want to use Realm Web instead of Realm, it's a different package: called realm-web
.
One other alternative you may be interested in for accessing data in Atlas is the Atlas Data API.
Its an Angular Web App with SSR. Realm Web (according to the docs) can not be used in node.js. So for the Server Side Rendering I would use Realm and once the app is rendered in the browser I would use Realm Web. Your SDK's have alienated an entire framework user base, probably the number 2 SPA tech in the world. All of your competitors (that I am aware of) use a single js sdk for browser and node server. The only reason I am tolerating the issues with your sdk's is because I really want to use MongoDB (database), but I am second guessing that decision. Has the Realm team ever bothered to test your sdk's with the number 2 javascript framework? Using Angular and Realm together one has to give up SEO all together, no SSR and no way to generate static pages because that requires node runtime.
The Atlas Data API is still in preview. And aside from the API Key there does not seem to be a data-access rules mechanism like with Realm Apps. So the Data API is not very useful to those that are looking to not build a backend.
@tomduncalf like I said in my first comment... "ditch the legacy port and rewrite your SDK's using modern module patterns for javascript apps".
https://github.com/realm/realm-js/issues/1060#issuecomment-465934019
AWS Amplify, Firebase, FaunaDB, etc... all have modern implementations of their JS SDK's. MongoDB cut corners and used a legacy implementation to cobble into a modern javascript ecosystem. Depressing to say the least.
Hi @jbeckton, sorry to hear this is causing so many issues for you.
The realm
module is only for use with Node.js, Electron and React Native. The library is primarily written in C++, so it needs to use Node or React Native's native modules capability to be able to run this native code. This doesn't just apply to Angular, you would also be unable to use the realm
package with React on web.
However, you should be able to use realm-web
with Node, see https://github.com/realm/realm-js/tree/master/packages/realm-web#using-realm-web-in-a-nodejs-environment.
If you are still having issues, please could you open a new issue with details?
Thanks
Hi @jbeckton Product for Realm here, as Tom mentioned, the realm package is designed for mobile applications or client-side devices, it works as an embedded database and stores data directly to disk. In a browser, there is no access to disk which is why we have a separate package called realm-web that does not have this database component. If you are building a server-side app, which sounds like you are if you are trying to build a node.js server that performs SSR, then we would recommend using the MongoDB node.js driver here - https://www.mongodb.com/docs/drivers/node/current/
If you want to leverage Realm's Data Access rules you can still do that with the MongoDB driver by directing the wire protocol through the Realm middleware tier - you can see how to do this here - https://www.mongodb.com/docs/realm/mongodb/wire-protocol/
You also mentioned Amplify and Fauna which are primarily GraphQL services, Realm Cloud also has a GraphQL service which you can leverage here - https://www.mongodb.com/docs/realm/graphql/
Hopefully these are enough options to direct you on the correct path
@ianpward As I said before, I am building a SPA and I just want to use Realm app services to talk to MongoDB Atlas cluster while utilizing authentication and access rules so that I do not have to build a backend. I don't care for the Realm embedded database, I don't plan on using it. I am trying to use realm-web and realm, they both have a mongoClient implementation that is very similar to the MongoDB driver that will allow me to interact with the collections stored in an Atlas cluster. I need to Talk to an Atlas cluster from the client browser and from node.js server within the same codebase.
Has anyone at MongoDB ever thought of testing this? My tech stack is about as common as you can get, everyone is doing SSR / SPA now days and your SDK's don't work for this very common scenario because there has to be two of them for javascript apps. I did manage to get realm and realm-web working together with Next.js but only with a bastardized architecture that makes it difficult to share code between the browser and node environments. My current experiments are super simple and I am not yet convinced this will scale. My preferred framework is Angular and that venture was an epic failure trying to use realm and realm-web together with Angular. Did you guys ever think to try realm with Angular Universal?
Realm App Services is a JamStack concept yet you don't even provide an SDK that will run within a JamStack environment. If a developer wants SEO for their app your SDK either makes it impossible or requires an awful architecture to juggle two different SDK's as a work around.
I invite you to go look at Google's Firebase SDK's, what a great developer experience! But Firestore is not an ideal database platform for what I need, MongoDB is. Realm SDK's are ruining it for me though.
Your SDK's just don't provide a productive experience for web developers, it's unfortunate because MongoDB is a great database platform. In this day and age a web developer can build a full-stack web app and a mobile app all with javascript and have the luxury of sharing code between them all. Realm has shot that idea in the foot with your SDK's.
@jbeckton Could you please open a new issue to discuss this further?
My understanding is that it should be possible to use realm-web for both Node and web usage, so your app code can be isomorphic, but I have not tried this myself. If you need help with this, please open an issue with some details of what didn't work.
Equally if you have some concrete ideas for how we could improve the developer experience, please feel free to open a new issue with details, we always welcome feedback.
Thanks
@jbeckton It would be interesting to know why these instructions did not work for you - https://github.com/realm/realm-js/tree/master/packages/realm-web#using-realm-web-in-a-nodejs-environment
Because @kraenhansen did try this successfully and ended up writing this instructions.
Hey @jbeckton, I've created a couple of sample projects which use realm-web to access data both on the server side and client side.
Here's the React version using Next.js: https://github.com/tomduncalf/realm-ssr-test, you can see the relevant changes in https://github.com/tomduncalf/realm-ssr-test/commit/6806cee707201e335aa118209a940cbbaf8b5d5d and I checked the data renders on both client (in browser) and server (with curl
)
Here's the Angular version: https://github.com/tomduncalf/realm-ssr-angular. I'm afraid I don't know how to use Angular so wasn't able to render the data to the screen, but I see the console.log
appear on both the browser and the terminal where I am running npm run dev:ssr
so I assume it is working. The relevant commit is: https://github.com/tomduncalf/realm-ssr-angular/commit/db0e3eff3a844494f3eb0386b9b6999b0d5d6939
Please take a look, hopefully this helps. If not please open a new Github issue with details of your problem, as this is beyond the scope of this original issue.
I am getting this error from this call to the SDK mongoClient?.db(dbName)
, it returns null
. The same exact code works properly when called in the proper context node vs web. Trying to use the realm-web sdk for both node and web does not work.
error - lib/realm/realmWebClient.ts (97:9) @ RealmWebClientService.db
Error: Could not find a database with the name basinsListDB_DEV
95 | const database = this.mongoClient?.db(dbName);
96 | if (!database) {
> 97 | throw new Error(`Could not find a database with the name ${dbName}`);
| ^
98 | }
99 | return database;
100 | }
error - lib/realm/realmWebClient.ts (97:9) @ RealmWebClientService.db
Error: Could not find a database with the name basinsListDB_DEV
95 | const database = this.mongoClient?.db(dbName);
96 | if (!database) {
> 97 | throw new Error(`Could not find a database with the name ${dbName}`);
| ^
98 | }
99 | return database;
100 | }
Please can you open a new issue @jbeckton and we will assist you there
@tomduncalf @ianpward I no longer need to open another issue for this. I was able to fix the previously posted error I was seeing after switching to the realm-web SDK for SSR operations.
In closing I ask you guys to put yourself in my position for a minute. I have wasted many hours of my free time trying get Realm App Services SDK's to work together because your official documentation clearly states...
The Web SDK does not support JavaScript or TypeScript applications written for the Node.js (server-side) environment...
But yet you have demonstrated that it indeed does here. I was under the impression that I had to figure out a way to juggle the 2 js SDK's so that I could have SSR and browser access to Realm App services because your official documentation leads one to this assumption. The React tutorial in your realm documentation relies on GraphQL and there is no SSR in that tutorial. The lack of transparency has caused a bit of frustration. I wonder how much revenue you are losing due to developers just giving up on Realm due to this?
As for the Angular community, If they manage to stumble upon the work around you provided you still have the issue with the bundle size caused by Realm SDK being 1MB just for an out of the box hello world app. The vendor bundle alone is HUGE even without all the other potential libraries that one could commonly use in an Angular application.
@jbeckton I'm glad you've got it working, and sorry that the docs misled you. I've raised an issue to update that part of the documentation as it is indeed incorrect, and hopefully in future we can add some more explicit documentation on SSR scenarios.
Bumping this. Have tried a few of the suggestions here with no success. Has anyone successfully resolved:
Failed to compile.
./node_modules/realm/lib/browser/index.js
Module not found: Can't resolve 'react-native' in '/Users/b/myApp/node_modules/realm/lib/browser'
Surely even without officially supporting electron - the team could offer some pointers? Thanking all in advance.Originally posted by @bentron2000 in https://github.com/realm/realm~~js/issues/1060#issuecomment~~464946917