From 1fda657cac9e1de5992efb02ec9be46bb1c745d9 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 2 Sep 2016 11:54:51 -0700 Subject: [PATCH] src: update module version mismatch error message Fixes: https://github.com/nodejs/node/issues/8379 PR-URL: https://github.com/nodejs/node/pull/8391 Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Benjamin Gruenbaum --- src/node.cc | 9 +++++++-- test/addons/node-module-version/binding.cc | 15 +++++++++++++++ test/addons/node-module-version/binding.gyp | 9 +++++++++ test/addons/node-module-version/test.js | 11 +++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/addons/node-module-version/binding.cc create mode 100644 test/addons/node-module-version/binding.gyp create mode 100644 test/addons/node-module-version/test.js 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);