问题标签 [node-addon-api]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
112 浏览

node.js - 本地存储节点插件事件以供以后回调

我在 javascript 中创建了两个事件,我可以通过 node-addon-api 成功调用它们。但我只能在调用插件函数后立即使用它们。有没有办法保存函数指针以供以后使用?

0 投票
0 回答
103 浏览

c++ - 试图从一个节点插件返回多个对象

我使用一个节点插件返回多个对象。

使用上述代码的 js 文件是这样的。

插件代码编译得很好,但是 js 给出了以下错误。致命错误:错误::新 napi_get_last_error_info 1: 00007FF68F1F046F napi_wrap+109311 2: 00007FF68F195156 v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::NumberOfElementsOffset+33302 3: 00007FF68F195156 : 00007FF68F1957C9 v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::NumberOfElementsOffset+34953 5: 00007FF68F1BE2EC napi_fatal_error+156 6: 00007FF8677D14E7 public: static void __cdecl Napi::Error::F __ptr64,char const * __ptr64)+23 7: 00007FF8677D1475 public: 静态类 Napi::Error cdecl Napi::Error::New(struct napi_env* __ptr64)+421 8: 00007FF8677D413C Napi::EscapableHandleScope::EscapableHandleScope+60 [C:\Project\abi-stable-node-addon-examples-master\7_factory_wrap\node-addon-api\node_modules\node-addon-api \napi-inl.h]:L3445

0 投票
2 回答
167 浏览

c++ - 使用 callbackInfo 在 linux 上运行 Napi 的问题

当使用 Windows 时,Napi 和我运行npm i它编译并且工作得很好。在 linux 上执行相同操作时,napi-inl.h 出现此错误

test.cc 看起来像这样

我不知道这是我的问题还是 NAPI 的问题

0 投票
1 回答
415 浏览

c++ - 如何在 node-addon-api 中从 c++ 返回 float32 数组?

我正在尝试使用 node-addon-api 在 node.js 中运行 c++。我从媒体上读过一篇写得很好的文章。但是我想将一个浮点数传递给我的一个函数,并将一个浮点数组传递给另一个函数。我想从他们两个返回一个浮点数组。函数示例 ( greeting.cpp)

index.cpp以及带有模块本机实现的代码:

问题是,Napi::Float32Array不起作用,我试过Napi::TypedArrayOf<float>了,它也不起作用。我不太喜欢编写模块。我只希望我在节点中运行的纯 c++ 代码将其结果发送到前端。我尝试接受和返回浮点数,Napi::Number它工作正常。但我不知道如何让它开始使用数组。任何帮助表示赞赏。

0 投票
0 回答
34 浏览

node.js - Node-Addon-Api 需要解构器吗?

我正在使用 Node-Addon-Api 在 NodeJS 中创建插件。每 30 秒调用一次插件函数,每次调用函数时都会创建 4 个双精度数组,最大数组大小为 2400 个值。我正在经历内存过载,所以我想知道这可能是因为在这 4 个数组上。我是否需要处理使用函数 New() 创建的每个对象?像Napi::Array::NewNapi::Number::New

例如:

Napi::Array plotHistory_Napi_out = Napi::Array::New(env, 2400);

我需要释放这个内存吗?如果是这样怎么办?
还是在作用域结束时自动发生?和 nodeJS GC 看到它并收集它?

如果有人可以帮助我,我将不胜感激,好吗?

0 投票
0 回答
239 浏览

node.js - 未定义的对“napi_create_function”的引用,使用 cmake 编译

我正在尝试编译用 c++ 编写的机器学习代码并使用 n-api 将其连接到 NodeJS,我在其中一个文件中编写了 NAPI 函数,并在 CMake 中定义了其他依赖项。

安装
'node-addon-api': '^3.0.0'
'cmake-js':'^6.1.0'

错误

CMakeLists.txt

主文件(program.cpp) 我注释了一些函数,同样的问题也出现在其他函数上。

0 投票
0 回答
173 浏览

javascript - 安装 gpu.js 后运行电子应用程序出错

我已经建立了一个电子应用程序。安装 gpu.js 库“npm install gpu.js --save”后。当我尝试运行电子应用程序时,它会出错。该应用程序使用 electron-forge 库编译和运行。

我已经为一些信号处理功能构建了一个电子应用程序。它从设备接收一些数据,然后对其进行处理并显示图表。

我已经使用 node-addon-api 实现了数据接收部分。我正在将接收到的数据从设备发送到 js,并希望使用 gpujs 库在 js 中实现信号处理。

安装 gpujs 库后,当我尝试运行该应用程序时。我收到此错误。我试图寻找解决方案,但对我没有任何帮助。

下面我还添加了整个日志以供参考:

0 投票
0 回答
109 浏览

webpack - 打包的应用程序无法在 electron-forge 中找到 .node 文件

我使用 electron-forge 构建了一个应用程序,其中添加了本机 Cpp 功能。

我已经解压了 electron-forge packagerConfigs 中的节点元素。

我正在使用绑定将节点插件导入我的应用程序。

在我已经使用脚本打包了应用程序

该节点正确放置在 asar.unpacked 文件夹中,并且在我的笔记本电脑中正常工作,但是当我将整个输出文件夹转移到另一台笔记本电脑时。它显示错误。

错误信息

文件位置包含节点文件的位置。

文件位置

当我使用 electron-forge make 构建安装程序并尝试在另一台笔记本电脑上运行它时。试图引用 .node 文件的临时文件夹。

请问有人可以帮我解决这个问题吗?谢谢

0 投票
0 回答
42 浏览

javascript - C++ 附加组件不在 express api 路由内部运行,但在外部运行

我在我的 Node.js 服务器上使用 C++ 插件。我正在尝试获取从文件中导入的解密函数,以便在命中 api 时运行,但解密什么也不做。相反,当我按照注释将解密留在路由之外时,它完全按预期工作。

我也尝试将它导入到路线的主体中,但没有帮助。

0 投票
0 回答
52 浏览

c++ - PortMidi Pm_OpenInput() function crash when running my c++ addon for NodeJS

I'm trying to make a simple DAW using Electron and C++ addons, and I want to use PortMidi for Midi keyboards support. I made a midi.h script to see if PortMidi works and I manage to compile and run the script with mingw-g++ (and it works), but when I build the nodejs addon using node-gyp, and run the app it shows this error during the execution of Pm_OpenInput(&midi_in, id, NULL, 0, NULL, NULL); (Which I believe means that the c++ script stopped for no reason...)

I generated the .lib and .dll files for PortMidi myself from this github repository https://github.com/philandstuff/portmidi using this command in a /build/ subfolder :

Here's my midi.h file:

And here's the main.cpp file I compiled with mingw-g++ to try PortMidi (and it works with g++)

Here's the binding.gyp file I'm using for node-gyp: (I only made the right includes for Windows)

I already tried to do node-gyp clean, .\node_modules\.bin\electron-rebuild, node-gyp configure, node-gyp build and rebuilding the necessary .lib and .dll files for OpenAL, sdnFile and PortMidi. I also tried using Pt_Start() and Pt_Stop() instead of making my own thread for the process_midi function, but it didn't changed anything.

I checked in the portmidi.c source file and it seems like the line 733 is causing the problem, but I'm a little bit lost ...

I'm on Windows 10 Pro with:

  • node-gyp v8.1.0
  • electron v13.1.2
  • node v14.16.0

The c++ addon works fine with sndFile and OpenAL, but only PortMidi don't work :/

All the source code from the app can be found here: https://github.com/FurWaz/FyneWav

If anyone could give me hints or suggest other c++ libraries for MIDI, that would be really helpful ^^ thanks !