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

nw:cannot find module #534

Closed
topwood opened this issue Oct 29, 2015 · 6 comments
Closed

nw:cannot find module #534

topwood opened this issue Oct 29, 2015 · 6 comments

Comments

@topwood
Copy link

topwood commented Oct 29, 2015

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 sqlite3@3.0.8 --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
Copy link
Author

topwood commented Oct 29, 2015

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

@Graham--M
Copy link

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.

@cyphunk
Copy link

cyphunk commented Feb 5, 2016

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
Copy link

cyphunk commented Feb 6, 2016

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

@Graham--M
Copy link

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.

@cyphunk
Copy link

cyphunk commented Feb 9, 2016

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 added a commit to cyphunk/snifferjs that referenced this issue Feb 9, 2016
…ather than a db.

mapbox sqlite3 module has issues in nw or eletron frameworks, which
I am slowly working snifferjs into. the problem is discussed:
TryGhost/node-sqlite3#534 (comment)
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

4 participants