When using windows the Napi and I run npm i
it compiles and works just fine. When doing the same on linux I get this error with the 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 looks like this
#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)
I don't know if this is an issue with me or with NAPI
It's because
npm i
are different on both Windows and Linux. Quoting an answer to another question: