1
votes

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 :

  1. info it worked if it ends with ok
  2. verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
  3. info using [email protected]
  4. info using [email protected]
  5. verbose run-script [ 'prestart', 'start', 'poststart' ]
  6. info lifecycle [email protected]~prestart: [email protected]
  7. info lifecycle [email protected]~start: [email protected]
  8. verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
  9. 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
  10. verbose lifecycle [email protected]~start: CWD: /home/vir4un/app/tanya/app
  11. silly lifecycle [email protected]~start: Args: [ '-c', 'node-gyp configure build && node index.js' ]
  12. silly lifecycle [email protected]~start: Returned: code: 1 signal: null
  13. info lifecycle [email protected]~start: Failed to exec start script
  14. verbose stack Error: [email protected] start: node-gyp configure build && node index.js
  15. verbose stack Exit status 1
  16. verbose stack at EventEmitter. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
  17. verbose stack at EventEmitter.emit (events.js:182:13)
  18. verbose stack at ChildProcess. (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
  19. verbose stack at ChildProcess.emit (events.js:182:13)
  20. verbose stack at maybeClose (internal/child_process.js:961:16)
  21. verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:250:5)
  22. verbose pkgid [email protected]
  23. verbose cwd /home/vir4un/app/tanya/app
  24. verbose Linux 4.15.0-33-generic
  25. verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
  26. verbose node v10.9.0
  27. verbose npm v6.4.1
  28. error code ELIFECYCLE
  29. error errno 1
  30. error [email protected] start: node-gyp configure build && node index.js
  31. error Exit status 1
  32. error Failed at the [email protected] start script.
  33. error This is probably not a problem with npm. There is likely additional logging output above.
  34. 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.

1

1 Answers

1
votes

Mosy likely you used the incorrect symbol in the module name. Such hello-world. Symbol - is prohibited.