Closed bsrdjan closed 6 years ago
I too have ran into this issue while installing node-ffi-napi
which depends on node-addon-api
.
Having a similar issue with 1.6.0 release
In file included from ../node_modules/node-addon-api/napi.h:1780,
from ../src/Reader.h:22,
from ../src/Reader.cc:19:
../node_modules/node-addon-api/napi-inl.h:3412:17: error: ‘napi_callback_scope’ has not been declared
napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
^~~~~~~~~~~~~~~~~~~
../node_modules/node-addon-api/napi-inl.h: In constructor ‘Napi::CallbackScope::CallbackScope(napi_env, int)’:
../node_modules/node-addon-api/napi-inl.h:3412:57: error: class ‘Napi::CallbackScope’ does not have any field named ‘_scope’
napi_env env, napi_callback_scope scope) : _env(env), _scope(scope) {
^~~~~~
../node_modules/node-addon-api/napi-inl.h: In constructor ‘Napi::CallbackScope::CallbackScope(napi_env, napi_async_context)’:
../node_modules/node-addon-api/napi-inl.h:3419:41: error: ‘_scope’ was not declared in this scope
_env, Object::New(env), context, &_scope);
^~~~~~
../node_modules/node-addon-api/napi-inl.h:3419:41: note: suggested alternative: ‘isctype’
_env, Object::New(env), context, &_scope);
^~~~~~
isctype
../node_modules/node-addon-api/napi-inl.h:3418:24: error: ‘napi_open_callback_scope’ was not declared in this scope
napi_status status = napi_open_callback_scope(
^~~~~~~~~~~~~~~~~~~~~~~~
../node_modules/node-addon-api/napi-inl.h:3418:24: note: suggested alternative: ‘napi_open_handle_scope’
napi_status status = napi_open_callback_scope(
^~~~~~~~~~~~~~~~~~~~~~~~
napi_open_handle_scope
../node_modules/node-addon-api/napi-inl.h: In destructor ‘virtual Napi::CallbackScope::~CallbackScope()’:
../node_modules/node-addon-api/napi-inl.h:3424:35: error: ‘_scope’ was not declared in this scope
napi_close_callback_scope(_env, _scope);
^~~~~~
../node_modules/node-addon-api/napi-inl.h:3424:35: note: suggested alternative: ‘isctype’
napi_close_callback_scope(_env, _scope);
^~~~~~
isctype
../node_modules/node-addon-api/napi-inl.h:3424:3: error: ‘napi_close_callback_scope’ was not declared in this scope
napi_close_callback_scope(_env, _scope);
^~~~~~~~~~~~~~~~~~~~~~~~~
../node_modules/node-addon-api/napi-inl.h:3424:3: note: suggested alternative: ‘napi_close_handle_scope’
napi_close_callback_scope(_env, _scope);
^~~~~~~~~~~~~~~~~~~~~~~~~
napi_close_handle_scope
../node_modules/node-addon-api/napi-inl.h: At global scope:
../node_modules/node-addon-api/napi-inl.h:3427:32: error: expected type-specifier before ‘napi_callback_scope’
inline CallbackScope::operator napi_callback_scope() const {
^~~~~~~~~~~~~~~~~~~
Getting this error with node 8.12.0, 10.9.0, and 11.1.0 Reverting node-addon-api back to 1.5.0 fixes this error.
Not sure if this is what is causing other peoples errors, but the one I was getting was caused by using the src/node-api.h instead of that in node itself. Removing
target_include_directories(${PROJECT_NAME}
PRIVATE
remove this---> ${CMAKE_SOURCE_DIR}/node_modules/node-addon-api/src
is all that was needed.
Same issue here - node.js v8.10.0, node-gyp v3.6.2, node-addon-api v1.6.0.
Hi everyone,
sorry for this. The problem is that we added Napi::CallbackScope
that use N-API function that has been released starting from Node.js v8.11.2. It works well on Node.js v8.12.0, v6.14.4, v10.x and 11.x. So I'm trying ti figure out how to solve the problem.
Hi @gabrielschulhof @mhdawson,
I take a look a this issue and what I discovered is that napi_open_callback_scope
and napi_close_callback_scope
is in Node.js 8 is available starting from the version 8.11.2. These two functions are available in the last version of Node.js 6 (v6.14.4) and in all Node 10 versions. What I'm trying to do is to exclude Napi::CallbackScope
where we don't have napi_open_callback_scopeand
napi_close_callback_scopefunctions. Do you have suggestions about this? Do we need to port the
napi_open_callback_scopeand
napi_close_callback_scope` in the internal version of N-API that is node-addon-api repo?
@NickNaso What about using the NODE_MAJOR_VERSION
and NODE_MINOR_VERSION
#DEFINE macros and placing the code behind an #ifdef
gate? I see some use of that pattern here: https://github.com/nodejs/node-addon-api/blob/master/src/node_internals.h
In a broader sense we may need to come up with a forward compatibility strategy for node-addon-api. N-API was so new that versioning differences between Node.js and the C++ wrapper weren't a concern until recently. Even if node-addon-api were to be aligned to the same major version strategy as Node.js, new minor version features will still cause compilation failures.
Probably should document the minimum version of Node.js that's needed and whenever that bumps increment the major version of node-addon-api. Node.js 8.10 is definitely going to be needed due to AWS Lambda and the way AWS (unfortunately) locks to a specific minor version of Node.
I think we have the required version management, we just missed guarding the new functionality with the right defines when we added the CallbackScope support. I should have caught that as part of the review.
Looking at fixing it now.
I believe this PR should resolve the issue: https://github.com/nodejs/node-addon-api/pull/395
@ebickle, @bsrdjan could one of you validate? I tested using the test suite, but I'd like to confirm that your re-world cases are resolved as well.
@mhdawson I updated one of our libraries to point to that specific commit and had a team test a built with it. They reported back that it worked with no errors. Dealing with a few different versions of NPM which makes things fun, but looks good.
@ebickle thanks !
Example: