Nw.js: [win] node native module doesn't work with renamed exe (was node-sqlite3 module don't work in node-webkit package mode)

Created on 20 Nov 2012  ·  56Comments  ·  Source: nwjs/nw.js

I've a problem with node-webkit v0.3.4 and node-sqlite3 module.
So, if I run my app with command nw C:\apps\packagedapp.nw my application work fine,
but if I create a package by command copy /b nw.exe+app.nw app.exe and launch it, my application crash whit error : Uncaught error: no error myPAth/node_sqlite3.node.

someone could help me
thanks

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

bug

Most helpful comment

@angufix Windows reports a dll module not found if any of its dependency not found. Your node_sqlite3.node depends on nw.exe, so it will fail when you rename nw.exe. You can see my sample code nw-addon-demo. There is a utility tool:

rename_import_lib\rename_import_lib.exe -i <path-to-node> [-o <path-to-output>] -r nw.exe <your-new-exe-name>

for your case

rename_import_lib\rename_import_lib.exe -i node_sqlite3.node -r nw.exe myapp.exe

Source code of rename_import_lib\rename_import_lib.exe also provided. It uses libpebliss.

All 56 comments

Can you provide the exact full error message? Thanks

happens to me too

nw v.0.3.2 , node_module compiled with your nw-gyp

here's my console error message

Uncaught Error: no error [%temporary directory%]\nw2340_27604\node_modules\sqlite3\node_sqlite3.node
source and line
module.js:485

thanks in advance

the error is in the function Module._extensions['.node'] in the module.js file in line 485

Hi, I try monolighter solution but i can't create a correct app.exe because when I start it node-webkit show nw:blank page.
I don't understand where I was wrong.. :-(

This could be a bug . I'll see what I can find and get back to you.

-------- Original Message --------
From: bicio [email protected]
Sent: Wed Nov 21 00:01:41 格林尼治标准时间+0800 2012
To: rogerwang/node-webkit [email protected]
Cc: Roger Wang [email protected]
Subject: Re: [node-webkit] node-sqlite3 module don't work in node-webkit package mode (windows) (#199)

Hi, I try monolighter solution but i can't create a correct app.exe because when I start it node-webkit show nw:blank page.
I don't understand where I was wrong.. :-(


Reply to this email directly or view it on GitHub:
https://github.com/rogerwang/node-webkit/issues/199#issuecomment-10560283

thank you very much

@monolighter as specified in the wiki, the plugin:true flag is useful for plugins like flash, not for nodejs modules

My wild guess is that the module DLL wants its dependency -- nw.exe, but after packaging, 'nw.exe' is renamed.

This guess could be tested by placing nw.exe beside app.exe to see what happens.

or just name the app executable nw.exe.

if I rename my app.exe in nw.exe work fine!

can i package .dll files with nw.exe and app.zip together ?

We are just about to integrate some custom node.js plugins and will run into this issue as well. Is there any plan to fix this in the near future? Could Gnor help with this?

Yeah. It can be done via rebuild on windows.

any update for this 10 months old bug?

is this problem had been fixed ?! @lvbeck @rogerwang @theabraham

No, I don't think so :/

Any planning for the fix of this error?
Is there already any good solution?

Hi
Any update for this bug yet?
It is really annoying all app must have nw.exe name.

Is there any plan to fix this bug? @rogerwang

@SingKo Since the issue is open, it's planned to be fixed. But there is no schedule yet.

This issue causes quite a maintenance problem for us and is the major reason why we don't upgrade node-webkit to later versions. If we can be of any assistance or help sponsor someone to work on this issue, then we'd be happy to consider that. Just let me know.

@rogerwang
Ah!!! do you have some suggestions for us about this bug? or any ideas to solve this problem?

It's due to the linking from VC tools, which injects the name of the exe into the module DLL.

The only known workaround is to rebuild NW on windows. Maybe binary patching the module DLL or nw.lib/nw.exp works too but I didn't try.

I rebuild NW on windows just now,and generate my native module with the new nw.lib,and it works!!!
thanks! @rogerwang

Could you tell me i have to patch which file in the source exactly?
I'm not very familiar with C/C++.
Thanks.

I modified the nw project to generate my.exe but not nw.exe,and it generate my.lib too,copy the my.lib to nw-gyp sdk,when you build your .node,link the my.lib but not nw.exe,then your .node will works well with my.exe.

So how do we fix this?
I have this problem on v0.8.4 width a native node module.
I get:
Uncaught Error: no error
when renaming nw.exe
Only way around this is to rebuild nw from scratch and all node modules?

@SingKo, can you tell me which files you modified to rebuild your project? I tried with ninja build but I got a error unknown target 'my.exe'

@lvbeck ,Its nw.gypi.But maybe you neednt modify it,just rebuild nw,and build your node-module with your new nw.lib.

Hi guys, any news on this ?

@SingKo I was not able to build a working copy of nw.exe with a different name based on your instructions.. Can you give us a more detailed step by step ?

Many thanks

@SingKo +1 to explain detailed step by step. Please!
Thank you.

@patrickklug It may be worth it to look at putting a bounty on the issue, now that nw is doing bountysource.

@rodrigopandini @damianb FYI I asked @SingKo by email about it and here is his reply :

I did not able to get it work either.

now I am using another app called deskshell, it has relatively small community but the maintainers are very friendly and willing to help.

@martindaniel4 @rodrigopandini ,sorry for reply you so late!
1,You have got a copy of nw src,open nw.gypi.
2,modify " 'target_name':'nw' " to '' 'target_name':'xxx' ",about in line 621.
3,modify " 'dependencies':['nw',] " to '' 'dependencies':['xxx',] ",about in line 588.
4,rebuild nw with ninja,like "ninja -C out/Release xxx -j8",you will get xxx.exe and xxx.lib.
5,to rebuild your sqlite3,if you have ever build your node addon with nw-gyp,you may have the nw-gyp sdk,the dir likes "C:\Users\Administrator.nw-gyp\0.8.5".
6,copy your xxx.lib to "C:\Users\Administrator.nw-gyp\0.8.5\Release".
7,modify your sqlite3 project file,make it link your xxx.lib but not nw.lib.
8,rebuild your sqlte3.
It should be work after you have done all steps above,just try it!

@SingKo
4,rebuild nw with ninja,like "ninja -C out/Release xxx -j8",you will get xxx.exe and xxx.lib.
Can you give us a more detailed step by step ?

Given the issue is quite old, I think it would be worth to mention it in the wiki in step 2b of https://github.com/rogerwang/node-webkit/wiki/How-to-package-and-distribute-your-apps.
That way, new users that want to package an app that includes native module would know not to rename the nw executable.
Personally, I didn't realize that step 2b above was incompatible with "Important Note 1" at the bottom of https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules.

@teh-skrud Good idea. Edits in the wiki are not restricted and thus you may mention that nuance in step 2b yourself.

@SingKo 's method does work!
I followed his instruction above and renamed the nw.exe sucessfully.
I use node-sqlite3 in my application. the whole process is complicate, not as easy as @SingKo 's instruction, each step you may encounter your own problem, but the instruction works.

Does this problem still exist?

Can't we just get the program name at run-time and pass it to the module after its loaded if it is really required?


In Example:
OllyDBG and IDA Pro plugins have it so the plugin will have a method exposed which is called by the process loading the plugin and will be used pass over anything required, including version numbers to check if the plugin was compiled for that version of the plugin api.

So for windows targets just export a hidden function like __nwmodule_init and give it the runtime information required. It should reply with the version of node webkit/ application binary interface it was compiled for then node webkit even if it is renamed could say yes or no to the module loading.

Or am I misunderstanding the complexity of this issue?
I may give it a go if this is still a problem.

This bug is really bumming me out.

In NW13 we are splitting the code as Chrome does on windows: ship nw.exe and nw.dll. Third party modules will be linking with nw.dll. Then the renaming of nw.exe won't break it.

that is a good idea if the same version is used on a system it will get around duplication of core functionality.

Just a thought, rather than copying the nw exe each time, it may be possible to make a shell extension/registry key on windows (i am not sure about other systems) to register a file extension that would run nw.exe on the directory or package / package.json chosen.

Similar to how java has jar files that can be opened in javaw by double clicking.
Is this something that has been considered or already done i must read more.

If a particular version of nw is required the package.json could say so and some sort of loader could load that core functionality to handle the process.

Great to hear Roger! Thanks for your hard work.

Until we get nw.dll, maybe this can help: NW.js with a custom executable name and native modules.

@ArielBadichi nice! will test it out!

@SingKo
how to rebuild nw with ninja.
Can you give us a more detailed step by step ?
thanks.

for me it doesnt work even if I rename the resulting exe from nw-builder to nw.exe. If I put my app files in the folder where original nw lives it works.

I am using leveldown in my app.

The killer solution seems to provide a PE manipulating tool to modify import table.
portable-executable-library or exported under my name looks great.
Since it supports:

  • Read 32- and 64-bit PE files (PE, PE+) for Windows, work similar with both formats
  • Read and write imports

You can see my demo nw-addon-demo.
It's tested OK for both ia32 and amd64.

Just renamed the nw.js to myapp.exe and run the exe file, the sqlite3(native module) can't handle it. Error log:

[8480:1215/172020:ERROR:gpu_child_thread.cc(146)] Exiting GPU process due to errors during initialization
[9188:1215/172020:ERROR:nw_shell.cc(335)] Error: The specified module could not be found.
C:\myapp\node_modules\sqlite3\lib\binding\node-webkit-v0.12.2-win32-ia32\node_sqlite3.node
at Error (native)
at Module.load (module.js:346:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:356:17)
at require (module.js:375:17)
at Object. (C:\myapp\node_modules\sqlite3\lib\sqlite3.js:4:15)
at Module._compile (module.js:451:26)
at Object.Module._extensions..js (module.js:469:10)
at Module.load (module.js:346:32)
at Function.Module._load (module.js:301:12)
[9188:1215/172020:INFO:CONSOLE(346)] "Uncaught Error: The specified module could not be found.
C:\myapp\node_modules\sqlite3\lib\binding\node-webkit-v0.12.2-win32-ia32\node_sqlite3.node", source: module.js (346)

@angufix Windows reports a dll module not found if any of its dependency not found. Your node_sqlite3.node depends on nw.exe, so it will fail when you rename nw.exe. You can see my sample code nw-addon-demo. There is a utility tool:

rename_import_lib\rename_import_lib.exe -i <path-to-node> [-o <path-to-output>] -r nw.exe <your-new-exe-name>

for your case

rename_import_lib\rename_import_lib.exe -i node_sqlite3.node -r nw.exe myapp.exe

Source code of rename_import_lib\rename_import_lib.exe also provided. It uses libpebliss.

This is supported in 0.13 now. Native modules depends on node.dll and nw.dll. And you can control the dependency. See more information here: https://groups.google.com/d/msg/nwjs-general/UqEq8ito2gI/W-ld9LSoDQAJ

@rogerwang not work with https://github.com/tojocky/node-printer

Hello guys, sorry to write on this old thread, but nw-gyp is too much for me, I'm left with no developers and trying to build myself is no use. According to the developers our application requires
nw-gyp 0.12.3
sqlite3 is built succesfully but seems misplaced in windows builds:
the usual:

Uncaught Error: Cannot find module 'C:\Users\F6FAA~1.CHI\AppData\Local\Temp\nw3056_13763\node_modules\sqlite3\lib\binding\node-webkit-v0.12.3-win32-x64node_sqlite3.node'

The app has been previously built successfully on linux 64 and working correcly.

After days of trying on a very steep learning curve, I'm here to ask to HIRE someone of you who would compile for windows. Please show up if available or give a few hints.

the environment I used:
node 5.6.0 (installed globally)
npm 3.6.0
python2.7
nw-gyp 3.4.0
node-pre-gyp 0.6.30
OS windows 7 professional
VStudio 2013

Set python path: npm config set python /Python27/python.exe --global

I removed every vs and c++ compiler from windows and installed vs express 2013 and set the environment variables.
"%VS120COMNTOOLS%"\vsvars32.bat // VS2013 environment variables with this from vs cmd worked.

Run visual studio shell as administrator.

The command I run
npm install;
npm run build;

cd build ; npm i :
cd ..
node nw-build.js (setting architecture and version win64, 0.12.3 )

I tried also to build separately and in the build directory
npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target="0.12.3"

I tryed to rename nw.exe myapp.exe but still the same error
.
Question: Should I use the module rename_import lib? or install nwjs instead of nw-gyp ?
at the moment I'm out of ideas

You are welcome for hire to build/document or for directions

Thank you
F

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Asp3ctus picture Asp3ctus  ·  4Comments

daverave1212 picture daverave1212  ·  3Comments

sorty-zz picture sorty-zz  ·  4Comments

azer picture azer  ·  3Comments

xzh-loop picture xzh-loop  ·  3Comments