question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

“Module did not self-register” when page is reloaded

See original GitHub issue

The first time I run my NW.js application the modules are loaded without errors (and works). If I refresh the page (CTRL+R, F5 or SHIFT+F5) I get the error: Module did not self-register. This only happens when ffi or ref is required.

const ffi = require('ffi');
const ref = require('ref');

In Electron it works without problems.

ffi and ref were installed using npm install ffi and npm install ref followed by nw-gyp rebuild --target=0.18.8 --arch=ia32 from each of the two folders node_modules/ffi and node_modules/ref

Any ideas?

nw.js v0.18.8   
Node v7.2.0   
Chromium 54.0.2840.99   
ffi@2.2.0  
ref@1.3.3

Here’s the full error output:

Uncaught Error: Module did not self-register.(…)
  Module._extensions..node	@	VM1704 module.js:640
  Module.load	@	VM1704 module.js:512
  tryModuleLoad	@	VM1704 module.js:471
  Module._load	@	VM1704 module.js:463
  Module.require	@	VM1704 module.js:522
  require	@	VM1705 module.js:20
  bindings	@	C:\Users\Even\Desktop\nwjs-sdk-v0.18.8-win-ia32\app\node_modules\bindings\bindings.js:76
  (anonymous function)	@	C:\Users\Even\Desktop\nwjs-sdk-v0.18.8-win-ia32\app\node_modules\ref\lib\ref.js:5
  Module._compile	@	VM1704 module.js:595
  Module._extensions..js	@	VM1704 module.js:610
  Module.load	@	VM1704 module.js:512
  tryModuleLoad	@	VM1704 module.js:471
  Module._load	@	VM1704 module.js:463
  Module.require	@	VM1704 module.js:522
  require	@	VM1705 module.js:20
  (anonymous function)	@	C:\Users\Even\Desktop\nwjs-sdk-v0.18.8-win-ia32\app\node_modules\ffi\lib\ffi.js:6
  Module._compile	@	VM1704 module.js:595
  Module._extensions..js	@	VM1704 module.js:610
  Module.load	@	VM1704 module.js:512
  tryModuleLoad	@	VM1704 module.js:471
  Module._load	@	VM1704 module.js:463
  Module.require	@	VM1704 module.js:522
  require	@	VM1705 module.js:20
  (anonymous function)	@	C:\Users\Even\Desktop\nwjs-sdk-v0.18.8-win-ia32\app\FsuipcMonitor.js:22
  Module._compile	@	VM1704 module.js:595
  Module._extensions..js	@	VM1704 module.js:610
  Module.load	@	VM1704 module.js:512
  tryModuleLoad	@	VM1704 module.js:471
  Module._load	@	VM1704 module.js:463
  Module.require	@	VM1704 module.js:522
  require	@	VM1705 module.js:20
  self.require	@	VM1758:11
  (anonymous function)	@	mainpage_renderer.js:15

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
noviwidencommented, Sep 21, 2017

It seems as if you can’t re-require native modules (.node files) in Node.js. Can it be related to this?

https://nodejs.org/dist/latest-v8.x/docs/api/modules.html#modules_require_cache https://github.com/nodejs/node/issues/6160 https://github.com/nodejs/node/issues/5016

I have the same problem, and worked around it for now by initializing the native module only in Node context, and then exposing it to the browser context via global. Only the browser context get reloaded on navigator.reload(). This solution only works without --mixed-context though, as far as I can see.

1reaction
rogerwangcommented, Dec 2, 2016

It should be a bug. Will look to fix it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NW.js - "Module did not self-register" when page is reloaded
If I refresh the page (CTRL+R, F5 or SHIFT+F5) I get the error: Module did not self-register . This only happens when ffi...
Read more >
Fix the Module did not self-register error in Node.js - Reactgo
In this tutorial, we are going to learn about how to fix the Module did not self-register error in Node.js. When we run...
Read more >
`netlify dev` reload causes error: "Module did not self-register ...
`netlify dev` reload causes error: "Module did not self-register" with node-canvas · Describe the bug. Any time I change any file inside my ......
Read more >
Error: Module did not self-register-angular.js - appsloveworld
Coding example for the question Binary has a problem: Error: Module did not self-register-angular.js.
Read more >
nwjs/nw.js - Gitter
The 'loaded' event does get fired but that happens only AFTER page reload so ... a 'Module did not self-register' error as native...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found