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

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

Open
EvenAR opened this issue Dec 2, 2016 · 15 comments
Open

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

EvenAR opened this issue Dec 2, 2016 · 15 comments
Assignees

Comments

@EvenAR
Copy link

EvenAR commented Dec 2, 2016

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
@rogerwang rogerwang self-assigned this Dec 2, 2016
@rogerwang
Copy link
Member

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

@rogerwang
Copy link
Member

I can't reproduce this with a simple case and requiring 'ref'. Could you please provide a case?

@EvenAR
Copy link
Author

EvenAR commented Dec 5, 2016

Sorry, I forgot to mention that I'm using the 32 bit version of NW.JS all modules are installed using --arch=ia32.

Here's a simple case:
main_page.html:

<!DOCTYPE html>
<html>
	<head>
		<h1>Hello world</h1>
	</head>
	<script>
		const ref = require('ref')
	</script>
</html>

Here's my package.json:

{
    "app_name": "app",
    "dependencies": {
        "ref": "^1.3.3"
    },
    "main": "main_page.html",
    "name": "nw-demo",
    "nodejs": true,
    "version": "0.0.1",
    "window": {
        "frame": false,
        "id": "app",
        "title": "app"
    }
}

EDIT:
Hmm, this case actually seems to work now and then.. I will do some more troubleshooting in my big app..

@EvenAR
Copy link
Author

EvenAR commented Dec 6, 2016

Looks like the error is related to the use of

"chromium-args": "--mixed-context"

in package.json. Placing this line in the file shown in my previous post triggers the error when a page is reloded.

@Christywl
Copy link
Contributor

I can't reproduce this issue with the reporter's test case on Linux and nwjs-sdk-0.21.0. It works fine even if I put "chromium-args": "--mixed-context" in package.json.

@rogerwang
Copy link
Member

close until more information is provided.

@KiresMA
Copy link

KiresMA commented Apr 19, 2017

@rogerwang I have this issue with two windows and mixed-context enabled.
NW version: 0.21.2 , ia32
OS: Win 7

Let's say the window we put in package.json is a loading window (some splash screen). From this loading page we open our main window where we require the 'ffi' module.
The first time you run the app everything will work, but after refreshing the page the error: "Module did not self-register" appears.

It happens only with mixed-context enabled.

Here is the case:
package.json

{
    "name": "test-ffi",
    "main": "loading.html",
    "version": "0.1.0",
    "window": {
        "title": "tets FFI",
        "width": 500,
        "height": 300,
        "frame": false,
        "resizable": false
    },
    "chromium-args": "--mixed-context",
    "dependencies": {
        "ffi": "2.2.0"
    }
}

loading.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Loading page</title>
</head>
<body onload="loaded()">
    <h1>Loading...</h1>
    <script>
        var loadingWin = nw.Window.get();

        function showMainWindow() {
            nw.Window.open('index.html', {
                focus: true,
                position: 'center',
                width: 1000,
                height: 700,
                min_width: 1280,
                min_height: 740,
                frame: true,
                show: false
            }, function (w) {
                w.on('loaded', function () {
                    w.show();
                    loadingWin.close();
                });
            });
        }

        function loaded() {
            setTimeout(showMainWindow, 2000);
        }
    </script>
</body>
</html>

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>FFI test</title>
</head>
<body>
    <h1>Ffi TEst</h1>
    <script>
        var ffi = require('ffi');
    </script>
</body>
</html>

@KiresMA
Copy link

KiresMA commented May 8, 2017

@rogerwang Is there any updates on this issue?

@rogerwang rogerwang reopened this May 8, 2017
@rogerwang
Copy link
Member

CC @Christywl , please try with @KiresMA 's example.

@Christywl
Copy link
Contributor

@KiresMA , I try your sample, but there is an error in my device(Windows 10 64bit).
My steps:

  1. create a folder named 5522 and create package.json loading.html index.html with your codes
  2. npm install
  3. nwjs-sdk-v0.22.1-win-x64\nw.exe 5522\

The app starts, but an error occurs in the devtools console:
5522

I also try to reload the app, there is no "Module did not self-register". May be it's blocked by the above error.
(you said refresh the page, does it mean 'reload the app'? )

Do you have any ideas about this error?

@KiresMA
Copy link

KiresMA commented May 8, 2017

@Christywl "you said refresh the page, does it mean 'reload the app'?" - Yes, it does.

I forgot to mention that after $npm install I'm rebuilding ffi and ref modules with:
$nw-gyp rebuild --target=0.21.2
Maybe this will be the case..

Also please try to use both NodeJS and NWjs ia32 architecture (like I did) or at least just check whether they are both x64.

Here are my device params:

  • Windows 7 - x64;
  • NodeJS - x86, v7.5.0
  • NWjs - ia32, v0.21.2

@Christywl
Copy link
Contributor

@KiresMA , thanks for your advice. It works well for me after rebuild ffi and ref. There is no error in the console after I right-click to reload the app.
5522-1

Environments:

- Node: v7.8.0 x64
- NWjs: win-sdk-v0.21.2-x64
- Windows 10 x64
- Node: v7.5.0 x86
- NWjs: win-sdk-v0.21.2-ia32
- Windows 10 x64

@KiresMA
Copy link

KiresMA commented May 9, 2017

@Christywl Try to:

  1. run the app
  2. open dev tools
  3. click F5 OR CTRL+SHIFT+R on the opened DevTools

@Christywl
Copy link
Contributor

I reproduce this issue now. Press F5, not right-click to reload the app.

@noviwiden
Copy link

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
nodejs/node#6160
nodejs/node#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants