Skip to content

Commit 1fda657

Browse files
committed
src: update module version mismatch error message
Fixes: #8379 PR-URL: #8391 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 96b501d commit 1fda657

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/node.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -2406,8 +2406,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
24062406
char errmsg[1024];
24072407
snprintf(errmsg,
24082408
sizeof(errmsg),
2409-
"Module version mismatch. Expected %d, got %d.",
2410-
NODE_MODULE_VERSION, mp->nm_version);
2409+
"The module '%s'"
2410+
"\nwas compiled against a different Node.js version using"
2411+
"\nNODE_MODULE_VERSION %d. This version of Node.js requires"
2412+
"\nNODE_MODULE_VERSION %d. Please try re-compiling or "
2413+
"re-installing\nthe module (for instance, using `npm rebuild` or"
2414+
"`npm install`).",
2415+
*filename, mp->nm_version, NODE_MODULE_VERSION);
24112416

24122417
// NOTE: `mp` is allocated inside of the shared library's memory, calling
24132418
// `uv_dlclose` will deallocate it
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <node_version.h>
2+
#undef NODE_MODULE_VERSION
3+
#define NODE_MODULE_VERSION 42
4+
#include <node.h>
5+
6+
namespace {
7+
8+
inline void Initialize(v8::Local<v8::Object> exports,
9+
v8::Local<v8::Value> module,
10+
v8::Local<v8::Context> context) {
11+
}
12+
13+
}
14+
15+
NODE_MODULE_CONTEXT_AWARE(binding, Initialize)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
6+
'sources': [ 'binding.cc' ]
7+
}
8+
]
9+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
require('../../common');
4+
const assert = require('assert');
5+
6+
const re = new RegExp(
7+
'was compiled against a different Node.js version using\n' +
8+
'NODE_MODULE_VERSION 42. This version of Node.js requires\n' +
9+
`NODE_MODULE_VERSION ${process.versions.modules}.`);
10+
11+
assert.throws(() => require('./build/Release/binding'), re);

0 commit comments

Comments
 (0)