diff --git a/src/node_api.cc b/src/node_api.cc index fb3ea5df2ce006..a83244131ff5a8 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -868,6 +868,12 @@ void napi_module_register_by_symbol(v8::Local exports, v8::Local module, v8::Local context, napi_addon_register_func init) { + if (init == 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)