Skip to content
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

Realm not working with Bunjs #6168

Open
ansarizafar opened this issue Oct 2, 2023 · 6 comments
Open

Realm not working with Bunjs #6168

ansarizafar opened this issue Oct 2, 2023 · 6 comments

Comments

@ansarizafar
Copy link

ansarizafar commented Oct 2, 2023

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
Copy link
Contributor

kneth commented Oct 2, 2023

@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:

  • Integration will Bun's event loop
  • Add integration with JavaScriptCore (a target in our binding generator)
  • Integrate with Bun's initialization of C++ code

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

@ansarizafar
Copy link
Author

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
Copy link

  • 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
Copy link
Contributor

kneth commented Oct 3, 2023

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
Copy link
Author

Is there any new update? I badly need this.

@ianpward
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants