here is the console after node-gyp configure build && node index.js
- In file included from ../test.cc:1:0:
- :0:26: error: expected initializer before ‘-’ token
- /home/vir4un/.node-gyp/10.9.0/include/node/node_api.h:74:15: note: in definition of macro ‘NAPI_C_CTOR’
- static void fn(void) attribute((constructor)); \
- /home/vir4un/.node-gyp/10.9.0/include/node/node_api.h:104:3: note: in expansion of macro ‘NAPI_MODULE_X’ NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
- ../test.cc:47:1: note: in expansion of macro ‘NAPI_MODULE’ NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
- ../test.cc:47:13: note: in expansion of macro ‘NODE_GYP_MODULE_NAME’ NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
also
- gyp ERR! build error
- gyp ERR! stack Error:
make
failed with exit code: 2- gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:262:23)
- gyp ERR! stack at ChildProcess.emit (events.js:182:13)
- gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:239:12)
- gyp ERR! System Linux 4.15.0-33-generic
- gyp ERR! command "/usr/bin/node" "/usr/bin/node-gyp" "configure" "build"
- gyp ERR! cwd /home/vir4un/app/tanya/app
- gyp ERR! node -v v10.9.0
- gyp ERR! node-gyp -v v3.8.0
- gyp ERR! not ok
also here is debug log :
- info it worked if it ends with ok
- verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
- info using [email protected]
- info using [email protected]
- verbose run-script [ 'prestart', 'start', 'poststart' ]
- info lifecycle [email protected]~prestart: [email protected]
- info lifecycle [email protected]~start: [email protected]
- verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
- verbose lifecycle [email protected]~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/vir4un/app/tanya/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
- verbose lifecycle [email protected]~start: CWD: /home/vir4un/app/tanya/app
- silly lifecycle [email protected]~start: Args: [ '-c', 'node-gyp configure build && node index.js' ]
- silly lifecycle [email protected]~start: Returned: code: 1 signal: null
- info lifecycle [email protected]~start: Failed to exec start script
- verbose stack Error: [email protected] start:
node-gyp configure build && node index.js
- verbose stack Exit status 1
- verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
- verbose stack at EventEmitter.emit (events.js:182:13)
- verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
- verbose stack at ChildProcess.emit (events.js:182:13)
- verbose stack at maybeClose (internal/child_process.js:961:16)
- verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
- verbose pkgid [email protected]
- verbose cwd /home/vir4un/app/tanya/app
- verbose Linux 4.15.0-33-generic
- verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
- verbose node v10.9.0
- verbose npm v6.4.1
- error code ELIFECYCLE
- error errno 1
- error [email protected] start:
node-gyp configure build && node index.js
- error Exit status 1
- error Failed at the [email protected] start script.
- error This is probably not a problem with npm. There is likely additional logging output above.
- verbose exit [ 1, true ]
here is test.cc :
#include <node_api.h>
napi_value MyFunction(napi_env env, napi_callback_info info) {
napi_status status; size_t argc = 1; int number = 0; napi_value argv[1]; status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);if (status != napi_ok) { napi_throw_error(env, NULL, "Failed to parse arguments"); }
status = napi_get_value_int32(env, argv[0], &number);
if (status != napi_ok) { napi_throw_error(env, NULL, "Invalid number was passed as argument"); } napi_value myNumber; number = number * 2; status = napi_create_int32(env, number, &myNumber);
if (status != napi_ok) { napi_throw_error(env, NULL, "Unable to create return value"); }
return myNumber; }
napi_value Init(napi_env env, napi_value exports) { napi_status status; napi_value fn;
status = napi_create_function(env, NULL, 0, MyFunction, NULL, &fn); if (status != napi_ok) { napi_throw_error(env, NULL, "Unable to wrap native function"); }
status = napi_set_named_property(env, exports, "my_function", fn);
if (status != napi_ok) { napi_throw_error(env, NULL, "Unable to populate exports"); }return exports; }
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
// they said it is on node_api.h , i don't even edit the original file. it kill me inside.