-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Implement Node-API in bun.js (napi) #158
Comments
I made a test repo that exercises a number of things that are currently having problems with the bun napi interface:
You will have uncomment NAPI_MODULE from apw.cpp (and comment NODE_MODULE_INIT) when you want to test that, figured the other things were more important. Hope that helps, thanks for the great work! |
I also wanted to check to see if this is roughly the right approach loading a module for napi + ffi usage. I think the hybrid strategy is good: use napi for general purpose stuff like building objects, async work, and use ffi for "hot" functions that need to be fast. Here is an example from my code where I am loading the platform's binary with the napi loading package, and then, if running in bun, loading it through the FFI loader. But, I think this raises a couple points:
Anyway, here is my loading sequence right now:
|
For bun you can also do
This is a good point. I don't know either, but worth checking.
This is an oversight – require.resolve should exist but does not currently. There are at least 5 other ways you can resolve without loading modules though:
|
My evidence is that when I set the value of a static C variable from a NAPI call, that value was accessible/correct from an FFI call, so I think working correctly, but I am not claiming this as absolute proof.
Ok, so you plan on adding require.resolve? I think in node-gyp-build it would either need to go through Anyway, thanks for the progress here, I know these are probably annoying details of the napi/node machinery, but I think node-gyp-build is pretty commonly used. |
Support for both of these was added in Bun v0.0.83 (released today) |
FYI, I tried to run parcel-css with Bun, but got the following error (logging with
Example: const parcelCss = require('./parcel-css.darwin-arm64.node');
parcelCss.transform({
filename: 'test.css',
code: Buffer.from('.foo { color: red }'),
minify: true
}); |
If I attempt to load a native module that uses Node-API, I get a crash on missing symbols. Additionally, I don't see any of the Node-API symbols in the bun binary (0.1.1, macOS x86_64). Is there something additional that needs to be done to load these symbols or was this possibly optimized out in the latest release?
Edit: It appears to be only the macOS release where they are missing. The symbols are present in linux. |
What do you mean by As bluebird uses async_hooks and requires it explicitly like this for example:
Which then results into:
|
async_hooks will need to be polyfilled but initially just disabled so it is
a no-op rather than failure on require()
Also in bun at least, you should try to avoid Bluebird. It’s a many X
slowdown
…On Sun, Jul 10, 2022 at 10:13 AM Laurens Lavaert ***@***.***> wrote:
What do you mean by async_hooks resource tracking will not be supported,
it will just ignore them.
As bluebird uses async_hooks and requires it explicitly like this for
example:
var AsyncResource = util.isNode && util.nodeSupportsAsyncResource ?
require("async_hooks").AsyncResource : null;
Which then results into:
Could not resolve: "async_hooks". Maybe you need to "bun install"?
—
Reply to this email directly, view it on GitHub
<#158 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFNGSZC646YQEGC6NGCNRTVTMAFNANCNFSM5VDV6N3Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
What would you say is recommended to use (instead)? Par example, (async () => { for (let i=0; i<800000; i++) { await functionCall(i); } })(); ...would work, but only one execution at a time. P. S. http://bluebirdjs.com/docs/benchmarks.html claims to be faster (in node) than async-await. |
PrismaJS also requires async_hook |
Hey folks! Is there any progress on |
Added in dddbce8 |
When running @parcel/watcher, even just trying to import it with |
Yes, there are at least three issues blocking |
Looks like |
@Jarred-Sumner Either I did something wrong or did not help :-/ |
Sorry, please try again after 4be3548 |
The above mention from an issue in keccak is interesting:
But using bun: The build succeeds and the node-gyp-build require succeeds...... returning an empty object So our fallback mechanism doesn't work with bun and users get cryptic errors (see the issue). It would be nice if bun could at least throw an error when it tries to build / run something it can't support, that way our existing mechanism would have caught the issue. Let me know if this should be a separate issue. Thanks. |
Bun as of v1.0.3 imports Napi functions as object (in node: typeof x -> 'function', in bun: typeof x -> 'object'). |
Another compatibility request:
AFAICT this is an NAPI issue; let me know if that's not the case. This is blocking us from adopting Bun in a variety of our projects. |
@nwalters512 The |
@kjvalencik ah, that's unfortunate, thanks for looking into that! This is probably a difficult ask, but is it possible to make |
Hey guys! Any plans to support gdb output
lldb output
|
Any updates on this? |
|
i got the error at uWS.js also TypeError: symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module? |
@TomieAi |
hmm i know but i just wanna say uws dint work at bun sadly. throwing me error about "napi_register_module_v1" then i google about it XD and it leads me here. |
@TomieAi That issue would need to be filed with uWebSockets.js. This isn't an issue with |
For anyone experiencing NAPI issues with |
My issue regarding |
Node-API is Node.js' native addon API. The goal of this project is for many Node-API addons in bun.js to just work, without asking maintainers of node modules to make changes or rebuild their code specifically for Bun.
The first version will be scoped specifically to the
napi_*
functions. It will not include support foruv_*
functions or the V8 C++ functions. A good initial target is napi.rs support.Internal changes
.node
filesprocess.dlopen
support for native modulesrequire
support for native modulesAPI implementation
JSC::VM::lastException()
)Test coverage
The tentative plan is to rely on napi.rs tests, but haven't checked yet if that's possible.
The text was updated successfully, but these errors were encountered: