Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: update module version mismatch error message #8391

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2406,8 +2406,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& 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
Expand Down
15 changes: 15 additions & 0 deletions test/addons/node-module-version/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <node_version.h>
#undef NODE_MODULE_VERSION
#define NODE_MODULE_VERSION 42
#include <node.h>

namespace {

inline void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
}

}

NODE_MODULE_CONTEXT_AWARE(binding, Initialize)
9 changes: 9 additions & 0 deletions test/addons/node-module-version/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
'sources': [ 'binding.cc' ]
}
]
}
11 changes: 11 additions & 0 deletions test/addons/node-module-version/test.js
Original file line number Diff line number Diff line change
@@ -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);