node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

nw:cannot find module

Open topwood opened this issue 11 years ago • 6 comments

vrcraze@vrcraze-virtual-machine:/media/vrcraze/MyFiles/work_banch/nexe$ ~/Downloads/node-webkit-v0.8.6-linux-x64/nw . module.js:343 throw err; ^ Error: Cannot find module '/media/vrcraze/MyFiles/work_banch/nexe/node_modules/sqlite3/lib/binding/node-v11-linux-x64/node_sqlite3.node' at Function.Module._resolveFilename (module.js:341:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:367:17) at require (module.js:383:17) at Object.eval (/media/vrcraze/MyFiles/work_banch/nexe/node_modules/sqlite3/lib/sqlite3.js:4:15) at Module._compile (module.js:459:26) at Object.Module._extensions..js (module.js:477:10) at Module.load (module.js:359:32) at Function.Module._load (module.js:315:12) at Module.require (module.js:367:17)

node v0.10.26 ubuntu 14.06 x64 nw v0.8.6 sqlite3 v3.0.8 and i install sqlite3 usesudo npm install [email protected] --build-from-source --runtime=node-webkit --target_arch=x86 --target=0.8.6 and without error.

but when i use nw.js to run my app ~/Downloads/node-webkit-v0.8.6-linux-x64/nw . errors above fuck me. what can i do then? THX!

topwood avatar Oct 29 '15 04:10 topwood

I find in /node_modules/sqlite3/lib/binding there is a floader named "node-webkit-v0.8.6-linux-x86" which i suggest generated by nw-gyp .but why nw try to find binding/node-v11-linux-x64 rather than binding/node-webkit-v0.8.6-linux-x86

topwood avatar Oct 29 '15 04:10 topwood

Since the module appears in the correct path for the build options you supplied, you've probably built the native module correctly.

I assume from the build options that you are trying to run this on 32-bit nw-js. Since node-pre-gyp thinks you are on a 64-bit node-js, I would suspect you are accidentally running this on regular node-js.

If process.versions['node-webkit'] doesn't exist then you are running on regular node-js.

Graham--M avatar Nov 05 '15 14:11 Graham--M

Having same issue. If I manually linked the compiled .node into a path that the error indicates it is expected at, things work fine.

Recap: I compiled sqlite3 for nwjs-v0.12.3-linux-x64 on ubuntu 14 lts.

Installed with: npm install sqlite3 --runtime=node-webkit --target=0.12.3 --build-from-source --target_arch=x64

When running nw . I get an error saying the node_sqlite3.node could not be found. It is expecting to find it at node-v43-linux-x64 when infact it was compiled to ./node_modules/sqlite3/lib/binding/node-webkit-v0.12.3-linux-x64/node_sqlite3.node. To fix I made a link:

$ ls -l ./node_modules/sqlite3/lib/binding
total 8
lrwxrwxrwx 1 user user   90 Feb  5 18:12 node-v43-linux-x64 -> node-webkit-v0.12.3-linux-x64
drwxrwxr-x 2 user user 4096 Feb  5 18:11 node-webkit-v0.12.3-linux-x64

It shows that it is expecting. While this work around allows me to continue development it breaks any package/installation/sharing possibilities.

cyphunk avatar Feb 05 '16 17:02 cyphunk

I get exactly the same with using the Electron framework in place of NW/node-webkit, when using the electron official recommendations for installing modules. same solution

cyphunk avatar Feb 06 '16 19:02 cyphunk

The path gets built like so:

  1. /lib/sqlite3.js: calls node-pre-gyp.find() with the sqlite3 package.json
  2. /node_modules/node-pre-gyp/lib/pre-binding.js find():
    • validates (checks for existence really) the config in the node-sqlite3 package.json for these settings. Note the module_path which is has {parameters} that will be substituted.
    • Evaluates the information about the environment (the opts variable) and does a simple replacement of the {parameters} in the module_path.

So you likely want to check {runtime} here (node_modules/node-pre-gyp/lib/util/versioning.js) to see if it evaluates to "node-webkit" and {node_abi} also here which is determined from the value of runtime.

I think I see an issue with Electron. You can pass it in as the runtime option to node-pre-gyp because get_runtime_abi checks for it, but when runtime is determined from the enviroment you only have node-webkit or node. The code needs to check for process.versions['electron'].

Edit: Apparently there are at least two pull requests (1, 2) to fix the issue with Electron that have been sitting there for more than 2-3 months.

Graham--M avatar Feb 08 '16 19:02 Graham--M

Thanks for the links and clear trail. I wonder why they chose to have this setup. The few other native modules my application uses include their ".node" via a static unparameterised path. And they compile and work fine between nw/electron and node.

cyphunk avatar Feb 09 '16 15:02 cyphunk