diff --git a/src/node.cc b/src/node.cc index 5ced5a3db62461..ea4659b3a4cf17 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2406,8 +2406,13 @@ void DLOpen(const FunctionCallbackInfo& args) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), - "Module version mismatch. Expected %d, got %d.", - NODE_MODULE_VERSION, mp->nm_version); + "The module '%s'" + "\nwas compiled against a different Node.js version using" + "\nNODE_MODULE_VERSION %d. This version of Node.js requires" + "\nNODE_MODULE_VERSION %d. Please try re-compiling or " + "re-installing\nthe module (for instance, using `npm rebuild` or" + "`npm install`).", + *filename, mp->nm_version, NODE_MODULE_VERSION); // NOTE: `mp` is allocated inside of the shared library's memory, calling // `uv_dlclose` will deallocate it diff --git a/test/addons/node-module-version/binding.cc b/test/addons/node-module-version/binding.cc new file mode 100644 index 00000000000000..f46f0eb2c63645 --- /dev/null +++ b/test/addons/node-module-version/binding.cc @@ -0,0 +1,15 @@ +#include +#undef NODE_MODULE_VERSION +#define NODE_MODULE_VERSION 42 +#include + +namespace { + +inline void Initialize(v8::Local exports, + v8::Local module, + v8::Local context) { +} + +} + +NODE_MODULE_CONTEXT_AWARE(binding, Initialize) diff --git a/test/addons/node-module-version/binding.gyp b/test/addons/node-module-version/binding.gyp new file mode 100644 index 00000000000000..7ede63d94a0d77 --- /dev/null +++ b/test/addons/node-module-version/binding.gyp @@ -0,0 +1,9 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/node-module-version/test.js b/test/addons/node-module-version/test.js new file mode 100644 index 00000000000000..1095027a2e9522 --- /dev/null +++ b/test/addons/node-module-version/test.js @@ -0,0 +1,11 @@ +'use strict'; + +require('../../common'); +const assert = require('assert'); + +const re = new RegExp( + 'was compiled against a different Node.js version using\n' + + 'NODE_MODULE_VERSION 42. This version of Node.js requires\n' + + `NODE_MODULE_VERSION ${process.versions.modules}.`); + +assert.throws(() => require('./build/Release/binding'), re);