diff --git a/src/node_api.cc b/src/node_api.cc index ce54e22d55440e..3b47b647275065 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -866,6 +866,12 @@ void napi_module_register_cb(v8::Local exports, void* priv) { napi_module* mod = static_cast(priv); + if (mod->nm_register_func == nullptr) { + node::Environment::GetCurrent(context)->ThrowError( + "Module has no declared entry point."); + return; + } + // Create a new napi_env for this module or reference one if a pre-existing // one is found. napi_env env = v8impl::GetEnv(context); diff --git a/test/addons-napi/test_null_init/binding.gyp b/test/addons-napi/test_null_init/binding.gyp new file mode 100644 index 00000000000000..27701616e338db --- /dev/null +++ b/test/addons-napi/test_null_init/binding.gyp @@ -0,0 +1,8 @@ +{ + 'targets': [ + { + 'target_name': 'test_null_init', + 'sources': [ 'test_null_init.c' ] + } + ] +} diff --git a/test/addons-napi/test_null_init/test.js b/test/addons-napi/test_null_init/test.js new file mode 100644 index 00000000000000..6e6bf51839bed0 --- /dev/null +++ b/test/addons-napi/test_null_init/test.js @@ -0,0 +1,7 @@ +'use strict'; +const common = require('../../common'); +const assert = require('assert'); + +assert.throws( + () => require(`./build/${common.buildType}/test_null_init`), + /Module has no declared entry point[.]/); diff --git a/test/addons-napi/test_null_init/test_null_init.c b/test/addons-napi/test_null_init/test_null_init.c new file mode 100644 index 00000000000000..d9d2200488ce41 --- /dev/null +++ b/test/addons-napi/test_null_init/test_null_init.c @@ -0,0 +1,3 @@ +#include + +NAPI_MODULE(NODE_GYP_MODULE_NAME, NULL)