All was working good on node 7.
I've got 2 errors after upgrading from node 7 to node 8.
How can I fix this?
Thanks
Using Python 2.7
I get different errors (in Docker container or locally)
In Docker container:
make: Entering directory '/app/build'
CXX(target) Release/obj.target/node-api/node_modules/node-addon-api/src/node_api.o
../node_modules/node-addon-api/src/node_api.cc: In function ‘napi_status napi_async_init(napi_env, napi_value, napi_value, napi_async_context__**)’:
../node_modules/node-addon-api/src/node_api.cc:2806:3: error: ‘async_context’ is not a member of ‘node’
node::async_context* async_context = new node::async_context();
^
../node_modules/node-addon-api/src/node_api.cc:2806:24: error: ‘async_context’ was not declared in this scope
node::async_context* async_context = new node::async_context();
^
../node_modules/node-addon-api/src/node_api.cc:2806:44: error: expected type-specifier
node::async_context* async_context = new node::async_context();
^
../node_modules/node-addon-api/src/node_api.cc:2808:78: error: cannot convert ‘v8::Local<v8::String>’ to ‘const char*’ for argument ‘3’ to ‘node::async_uid node::EmitAsyncInit(v8::Isolate*, v8::Local<v8::Object>, const char*, node::async_uid)’
*async_context = node::EmitAsyncInit(isolate, v8_resource, v8_resource_name);
^
../node_modules/node-addon-api/src/node_api.cc: In function ‘napi_status napi_async_destroy(napi_env, napi_async_context)’:
../node_modules/node-addon-api/src/node_api.cc:2820:3: error: ‘async_context’ is not a member of ‘node’
node::async_context* node_async_context =
^
../node_modules/node-addon-api/src/node_api.cc:2820:24: error: ‘node_async_context’ was not declared in this scope
node::async_context* node_async_context =
^
../node_modules/node-addon-api/src/node_api.cc:2821:30: error: ‘async_context’ in namespace ‘node’ does not name a type
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2821:43: error: expected ‘>’ before ‘*’ token
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2821:43: error: expected ‘(’ before ‘*’ token
../node_modules/node-addon-api/src/node_api.cc:2821:44: error: expected primary-expression before ‘>’ token
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2821:60: error: expected ‘)’ before ‘;’ token
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc: In function ‘napi_status napi_make_callback(napi_env, napi_async_context, napi_value, napi_value, size_t, napi_value__* const*, napi_value__**)’:
../node_modules/node-addon-api/src/node_api.cc:2849:3: error: ‘async_context’ is not a member of ‘node’
node::async_context* node_async_context =
^
../node_modules/node-addon-api/src/node_api.cc:2849:24: error: ‘node_async_context’ was not declared in this scope
node::async_context* node_async_context =
^
../node_modules/node-addon-api/src/node_api.cc:2850:28: error: ‘async_context’ in namespace ‘node’ does not name a type
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2850:41: error: expected ‘>’ before ‘*’ token
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2850:41: error: expected ‘(’ before ‘*’ token
../node_modules/node-addon-api/src/node_api.cc:2850:42: error: expected primary-expression before ‘>’ token
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2850:58: error: expected ‘)’ before ‘;’ token
reinterpret_cast<node::async_context*>(async_context);
^
../node_modules/node-addon-api/src/node_api.cc:2852:18: error: ‘async_context’ in namespace ‘node’ does not name a type
static node::async_context empty_context = { 0, 0 };
^
../node_modules/node-addon-api/src/node_api.cc:2853:27: error: ‘empty_context’ was not declared in this scope
node_async_context = &empty_context;
^
../node_modules/node-addon-api/src/node_api.cc: In constructor ‘uvimpl::Work::Work(napi_env, v8::Local<v8::Object>, v8::Local<v8::String>, napi_async_execute_callback, napi_async_complete_callback, void*)’:
../node_modules/node-addon-api/src/node_api.cc:3338:23: error: no matching function for call to ‘node::AsyncResource::AsyncResource(v8::Isolate*&, v8::Local<v8::Object>&, v8::Local<v8::String>&)’
_complete(complete) {
^
In file included from /data/var/home/gonano/.node-gyp/8.0.0/include/node/node_buffer.h:25:0,
from ../node_modules/node-addon-api/src/node_api.cc:11:
/data/var/home/gonano/.node-gyp/8.0.0/include/node/node.h:591:5: note: candidate: node::AsyncResource::AsyncResource(v8::Isolate*, v8::Local<v8::Object>, const char*, node::async_uid)
AsyncResource(v8::Isolate* isolate,
^
/data/var/home/gonano/.node-gyp/8.0.0/include/node/node.h:591:5: note: no known conversion for argument 3 from ‘v8::Local<v8::String>’ to ‘const char*’
/data/var/home/gonano/.node-gyp/8.0.0/include/node/node.h:589:7: note: candidate: node::AsyncResource::AsyncResource(const node::AsyncResource&)
class AsyncResource {
^
/data/var/home/gonano/.node-gyp/8.0.0/include/node/node.h:589:7: note: candidate expects 1 argument, 3 provided
../node_modules/node-addon-api/src/node_api.cc: In static member function ‘static void uvimpl::Work::CompleteCallback(uv_work_t*, int)’:
../node_modules/node-addon-api/src/node_api.cc:3374:7: error: ‘CallbackScope’ was not declared in this scope
CallbackScope callback_scope(work);
^
node_modules/node-addon-api/src/node-api.target.mk:94: recipe for target 'Release/obj.target/node-api/node_modules/node-addon-api/src/node_api.o' failed
make: *** [Release/obj.target/node-api/node_modules/node-addon-api/src/node_api.o] Error 1
make: Leaving directory '/app/build'
Locally:
```
/project/node_modules/node-addon-api/napi.h:1072:12: error: unknown type name 'NAPI_NO_RETURN'
static NAPI_NO_RETURN void Fatal(const char* location, const char* message);
^
/project/node_modules/node-addon-api/napi.h:1072:27: error: expected member name or ';' after
declaration specifiers
static NAPI_NO_RETURN void Fatal(const char* location, const char* message);
~~~~~ ^
In file included from ../binding.cpp:4:
In file included from /project/node_modules/node-addon-api/napi.h:1449:
/project/node_modules/node-addon-api/napi-inl.h:421:24: error: use of undeclared identifier
'napi_create_double'
napi_status status = napi_create_double(env, val, &value);
^
/project/node_modules/node-addon-api/napi-inl.h:1427:3: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_get_last_error_info");
^~~~~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~~~^
/project/node_modules/node-addon-api/napi-inl.h:1432:7: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_get_and_clear_last_exception");
^~~~~~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~^
/project/node_modules/node-addon-api/napi-inl.h:1440:7: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_is_exception_pending");
^~~~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~~~^
/project/node_modules/node-addon-api/napi-inl.h:1444:9: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_get_and_clear_last_exception");
^~~~~~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~^
/project/node_modules/node-addon-api/napi-inl.h:1453:7: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_create_string_utf8");
^~~~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~^
/project/node_modules/node-addon-api/napi-inl.h:1461:20: error: no matching function for call
to 'napi_create_type_error'
status = napi_create_type_error(env, nullptr, message, &error);
^~~~~~
/Users/cla/.node-gyp/8.0.0/include/node/node_api.h:147:25: note: candidate function not viable: requires 3 arguments,
but 4 were provided
NAPI_EXTERN napi_status napi_create_type_error(napi_env env,
^
In file included from ../binding.cpp:4:
In file included from /project/node_modules/node-addon-api/napi.h:1449:
/project/node_modules/node-addon-api/napi-inl.h:1464:20: error: no matching function for call
to 'napi_create_error'
status = napi_create_error(env, nullptr, message, &error);
^~~~~
/Users/cla/.node-gyp/8.0.0/include/node/node_api.h:144:25: note: candidate function not viable: requires 3 arguments,
but 4 were provided
NAPI_EXTERN napi_status napi_create_error(napi_env env,
^
In file included from ../binding.cpp:4:
In file included from /project/node_modules/node-addon-api/napi.h:1449:
/project/node_modules/node-addon-api/napi-inl.h:1467:9: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::New", "napi_create_error");
^~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~^
/project/node_modules/node-addon-api/napi-inl.h:1476:10: error: no matching function for call
to 'New'
return Error::New(env, message, std::strlen(message), napi_create_error);
^~~~~
/project/node_modules/node-addon-api/napi.h:1095:19: note: candidate function not viable: no
known conversion from 'napi_status (napi_env, napi_value, napi_value )' (aka 'napi_status (napi_env__ *,
napi_value__ *, napi_value__ *)') to 'create_error_fn' (aka 'napi_status ()(napi_env__ *, napi_value__ *,
napi_value__ *, napi_value__ *)') for 4th argument
static TError New(napi_env env,
^
In file included from ../binding.cpp:4:
In file included from /project/node_modules/node-addon-api/napi.h:1449:
/project/node_modules/node-addon-api/napi-inl.h:1480:10: error: no matching function for call
to 'New'
return Error::New(env, message.c_str(), message.size(), napi_create_error);
^~~~~
/project/node_modules/node-addon-api/napi.h:1095:19: note: candidate function not viable: no
known conversion from 'napi_status (napi_env, napi_value, napi_value )' (aka 'napi_status (napi_env__ *,
napi_value__ *, napi_value__ *)') to 'create_error_fn' (aka 'napi_status ()(napi_env__ *, napi_value__ *,
napi_value__ *, napi_value__ *)') for 4th argument
static TError New(napi_env env,
^
In file included from ../binding.cpp:4:
In file included from /project/node_modules/node-addon-api/napi.h:1449:
/project/node_modules/node-addon-api/napi-inl.h:1483:8: error: unknown type name
'NAPI_NO_RETURN'
inline NAPI_NO_RETURN void Error::Fatal(const char* location, const char* message) {
^
/project/node_modules/node-addon-api/napi-inl.h:1483:23: error: expected unqualified-id
inline NAPI_NO_RETURN void Error::Fatal(const char* location, const char* message) {
^
/project/node_modules/node-addon-api/napi-inl.h:1496:5: error: no member named 'Fatal' in
'Napi::Error'
NAPI_FATAL_IF_FAILED(status, "Error::Error", "napi_create_reference");
^~~~~~~~~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:47:14: note: expanded from macro
'NAPI_FATAL_IF_FAILED'
Error::Fatal((location), (message)); \
~^
/project/node_modules/node-addon-api/napi-inl.h:1576:10: error: no matching function for call
to 'New'
return Error::New(env, message, std::strlen(message), napi_create_type_error);
^~~~~
/project/node_modules/node-addon-api/napi-inl.h:1560:22: note: candidate function not viable:
no known conversion from 'napi_status (napi_env, napi_value, napi_value )' (aka 'napi_status (napi_env__ *,
napi_value__ *, napi_value__ *)') to 'create_error_fn' (aka 'napi_status ()(napi_env__ *, napi_value__ *,
napi_value__ *, napi_value__ *)') for 4th argument
inline TError Error::New(napi_env env,
^
/project/node_modules/node-addon-api/napi-inl.h:1580:10: error: no matching function for call
to 'New'
return Error::New(env, message.c_str(), message.size(), napi_create_type_error);
^~~~~
/project/node_modules/node-addon-api/napi-inl.h:1560:22: note: candidate function not viable:
no known conversion from 'napi_status (napi_env, napi_value, napi_value )' (aka 'napi_status (napi_env__ *,
napi_value__ *, napi_value__ *)') to 'create_error_fn' (aka 'napi_status ()(napi_env__ *, napi_value__ *,
napi_value__ *, napi_value__ *)') for 4th argument
inline TError Error::New(napi_env env,
^
/project/node_modules/node-addon-api/napi-inl.h:1590:10: error: no matching function for call
to 'New'
return Error::New(env, message, std::strlen(message), napi_create_range_error);
^~~~~~~~
/project/node_modules/node-addon-api/napi-inl.h:1560:22: note: candidate function not viable:
no known conversion from 'napi_status (napi_env, napi_value, napi_value )' (aka 'napi_status (napi_env__ *,
napi_value__ *, napi_value__ *)') to 'create_error_fn' (aka 'napi_status ()(napi_env__ *, napi_value__ *,
napi_value__ *, napi_value__ *)') for 4th argument
inline TError Error::New(napi_env env,
^
´´´
@foxhound87 Please could you specify which version of node.js and node-addon-api you use (ex: 8.8.1) ?
I was using [email protected] with node js 7.0
The errors appears using [email protected] with node js 8.0
There were some changes in the N-API in 8.6 which included the 'last' of the planned breaking changes. For example a code was added when creating Errors. I wonder if you need to make sure to fully clean artifacts from past compilations. It is also possible that we missed some changes needed in the wrapper as we don't have complete testing yet.
Is your code public somewhere (ex a github repo we can pull and build ?
I'm out of the office today but will try to take a closer look tomorrow.
It's a private project and I cannot show the full code, but I can show a small part which is the export/init of the function I want to use in node.
String myFunction(const CallbackInfo& info) {
...
return String::New(info.Env(), otherFunction( ... ));
}
void Init(Env env, Object exports, Object module) {
exports.Set("myFunction", Function::New(env, myFunction));
}
NODE_API_MODULE(addon, Init)
This code needs to be updated?
Thank You.
And the binding.gyp file:
{
"targets": [
{
"target_name": "binding",
"sources": [
"binding.cpp"
],
"conditions": [
["OS=='mac'", {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
}
}]
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"cflags!": ["-fno-exceptions"],
"cflags_cc!": ["-fno-exceptions"],
"defines": ["NAPI_CPP_EXCEPTIONS"]
}
]
}
For the moment try to take a look here when I came back to home I can provide more useful examples
https://github.com/NickNaso/conf-ni-2017/blob/master/7-vedis-napi/src/binding.cc
I have the same problem, and here's my previous installation that worked with Node 7.x and node-addon-api 0.6.3: https://github.com/dashersw/brain-bits/blob/master/lib/bindings.cc
@foxhound87 Have you been solved your problem or do you need help?
@NickNaso I certainly need help ^^
@NickNaso thank you for the prompt reply.
I will change my code according to your code sample and I will let you know asap.
@dashersw This evening I will try to take a look at your repo
This needs an update
void Init(Env env, Object exports, Object module) {
exports.Set("myFunction", Function::New(env, myFunction));
}
The 'module' parameter was removed from the Init function. 1.0 had the 'last' of the breaking changes and this was one of them.
This is an an example of using the new signature:
The method now returns an Object, it can be either the exports object passed in or a new one that you create. I'd update your code to be:
Object Init(Env env, Object exports) {
exports.Set("myFunction", Function::New(env, myFunction));
return exports;
}
@dashersw I tried to recreate with your module but I get this error while doing the npm install.
npm WARN tar ENOENT: no such file or directory, open '/home/mhdawson/testmod/brain-bits/node_modules/.staging/promise-90622471/Readme.md'
npm WARN tar ENOENT: no such file or directory, open '/home/mhdawson/testmod/brain-bits/node_modules/.staging/source-map-b54b815a/Makefile.dryice.js'
npm ERR! code E404
npm ERR! 404 Not Found: electron@https://registry.npmjs.org/electron/-/electron-1.8.0.tgz
I updated the package json to use the 1.0.0 version of node-addon-api and am using Node.js 8.9.0
@foxhound87 can you let me know if the suggestions helped. Also above you said 8.0, can you try with 8.9.0 just so we are using the same version.
In my case using node 8.9, "bindings": "1.3.0", "node-addon-api": "1.1.0",
I solved using this code:
String myFunction(const CallbackInfo& info) {
...
return String::New(info.Env(), otherFunction());
}
Function CreateFunction(const CallbackInfo& info) {
Env env = info.Env();
Function fn = Function::New(env, myFunction, "myFunction");
return fn;
}
Object Init(Env env, Object exports) {
return Function::New(env, CreateFunction, "createObject");
}
NODE_API_MODULE(addon, Init)
then in node:
const MyObj = require('bindings')('myBindingName');
const myFunction = new MyObj();
const string = myFunction();
console.log('string:', string);
thanks for the support.