目录

How do I resolve the "Could not find usage of napi_module_register in napi_init.cpp." error when using the Node-API generation feature?

Symptom

An error occurs for generating glue code when you right-click a function and choose Generate... > NAPI from the shortcut menu.

Solution

Make sure the napi_module_register function is correctly called within the RegisterEntryModule function in the napi_init.cpp file. The parameter type of napi_module_register is napi_module*. The following figure shows the sample code for napi_module initialization. Then, generate the Node-API again.

The field meanings are as follows:

nm_version: Node-API module version.

nm_flags: module attribute flag.

nm_filename: file name of the Node-API module.

nm_register_func: registration function.

nm_modname: module name.

nm_priv: pointer to private data.

reserved: reserved field.