当使用windows时,Napi和我运行的是npm i,它可以编译并正常工作。当在linux上执行相同的操作时,我得到以下错误: napi-inl.h
project/node_modules/node-addon-api/napi-inl.h: In instantiation of ‘static Napi::Function Napi::Function::New(napi_env, Callable, const char*, void*) [with Callable = Napi::Promise (*)(Napi::CallbackInfo&); napi_env = napi_env__*]’:
../test.cc:10:50: required from here
project/node_modules/node-addon-api/napi-inl.h:1985:22: error: cannot bind non-const lvalue reference of type ‘Napi::CallbackInfo&’ to an rvalue of type ‘Napi::CallbackInfo’
1985 | typedef decltype(cb(CallbackInfo(nullptr, nullptr))) ReturnType;
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
project/node_modules/node-addon-api/napi-inl.h:1985:22: error: cannot bind non-const lvalue reference of type ‘Napi::CallbackInfo&’ to an rvalue of type ‘Napi::CallbackInfo’
project/node_modules/node-addon-api/napi-inl.h:1996:5: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
1996 | delete callbackData;
| ^~~~~~test.cc看起来像这样
#include <napi.h>
#include "processData.h"
// This is were the Node module function name is assigned
// when imported getData() will be the function to call
// It calls Process()
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "getData"),
Napi::Function::New(env, Process));
return exports;
}
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)我不知道这是我的问题还是纳皮的问题
发布于 2021-06-15 02:22:37
我发现这个问题只是一个简单的错误,涉及Process.cc中的函数声明缺少const关键字
老方法:
Napi::Promise Process(Napi::CallbackInfo& info)新方法:
Napi::Promise Process(const Napi::CallbackInfo& info)发布于 2021-05-18 07:05:57
这是因为npm i在Windows和Linux上是不同的。引用another question的答案
是的,如果您(或您的依赖项)使用原生node.js插件,可能会有所不同,这些插件是由node-gyp构建的,包含原生二进制代码。此外,在
package.json中也可能有操作系统/CPU特定的东西。可在此处找到package.json说明:https://docs.npmjs.com/files/package.json
https://stackoverflow.com/questions/67538203
复制相似问题