realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.76k stars 572 forks source link

Realm not working with Bunjs #6168

Open ansarizafar opened 1 year ago

ansarizafar commented 1 year ago

How frequently does the bug occur?

Always

Description

When I try to import realm in a js file and run the script with Bunjs, I get the following error error: Cannot find module "realm/realm-constants.json" from "/home/zafaransari/projects/bun/realmdb/node_modules/realm/dist/bundle.node.js"

Stacktrace & log output

error: Cannot find module "realm/realm-constants.json" from "/home/zafaransari/projects/bun/realmdb/node_modules/realm/dist/bundle.node.js"

Can you reproduce the bug?

Always

Reproduction Steps

install realm using command bun add realm import realm in a js file Run the js file with the command bun run index,js

Version

12.2.0

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Ubuntu 22.04.3 LTS

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

kneth commented 1 year ago

@ansarizafar Realm doesn't support Bun yet.

The error message you see is cause by the fact that Bun doesn't run the post-install script.

To support Bun is not a trivial project. It includes:

I will leave the issue open, and please upvote the issue if you believe Bun support is important for you.

ansarizafar commented 1 year ago

Bun is an important Javascript runtime which is faster than both Node and Deno. Realm must add support for Bun. I badly need it for our next project.

Jarred-Sumner commented 12 months ago
  • Integration will Bun's event loop
  • Add integration with JavaScriptCore (a target in our binding generator)
  • Integrate with Bun's initialization of C++ code

Bun implements napi, so a lot of the work is already done for you

We do not implement libuv symbols yet, and it looks like Realm is using libuv symbols when used with Node.js

https://github.com/realm/realm-js/blob/9913451f900a0e262ae312279acbe22a6cb46cc2/src/node/platform.cpp

If your target is >= C++17, you could probably get away with using std::filesystem instead

kneth commented 12 months ago

Thank you @Jarred-Sumner for pointing out that Bun is using N-API. Our dependency on libuv is a bit more complex than file operations: we rely heavily on the event loop to drive our change listeners, and we need to implement a scheduler for Bun's event loop. I guess we need to study Bun a bit closer.

ansarizafar commented 11 months ago

Is there any new update? I badly need this.

ianpward commented 11 months ago

the realm eng team does not intend to work on adding support for Bun at this time. Of course, Realm is open-source so you are more than free to take a swing at implementing it yourself. And we are happy to accept PRs back from our community.