mscdex / cap

A cross-platform binding for performing packet capturing with node.js
MIT License
360 stars 46 forks source link

`cap.node` undetected even after `node-gyp rebuild` #83

Closed rreed closed 5 years ago

rreed commented 5 years ago

Building an Electron app. This starts at, e.g., const cap = require('cap').Cap; as in the documentation.

C:\Users\RR\workspace\redacted\node_modules\cap\build\Release\cap.node
   at Object.eval (webpack-internal:///./node_modules/cap/build/Release/cap.node:1)
   at eval (webpack-internal:///./node_modules/cap/build/Release/cap.node:2)
   at Object../node_modules/cap/build/Release/cap.node (renderer.js:828)
   at __webpack_require__ (renderer.js:725)
   at fn (renderer.js:102)
   at eval (webpack-internal:///./node_modules/cap/lib/Cap.js:3)
   at Object../node_modules/cap/lib/Cap.js (renderer.js:839)
   at __webpack_require__ (renderer.js:725)
   at fn (renderer.js:102)
   at eval (webpack-internal:///./src/renderer/packet-capturer.ts:4)

Other folks are having similar problems, and fixed it with node-gyp rebuild or node-gyp configure rebuild; neither of these worked for me. (cap rebuilds, but this behavior doesn't actually change.)

Unit tests using the same also fail in the same way.

rreed commented 5 years ago

Double mystery: upgrading to npcap 0.991 instead of the version that is included with nmap (0.99-r2) fixes this problem. So in case anyone else sees the same, that fixed it for me. Will leave this open in case you need to fix anything, feel free to close it and sorry for wasting your time. :p

mscdex commented 5 years ago

Perhaps the npcap installed with nmap did not have WinPCap compatibility? That's the only issue I could think of that would cause this kind of problem.

rreed commented 5 years ago

So this broke again mysteriously, after doing npm install at some point. And now it works in the tests, but not when run under electron, rather than just being consistently broken everywhere.

Is there something I'm missing that is necessary to make this work in Electron always, rather than seemingly at random? :p (Likely just needs to be built a certain way, or...?)

mscdex commented 5 years ago

Electron, nwjs, etc. all have special ways of compiling node addons to work with their projects. A quick google search for Electron brings up this link.

rreed commented 5 years ago

For anyone else who wanders this way in the future: my problem was that I had cap in devDependencies, not dependencies, and electron-rebuild was not playing nicely with that fact. This seems to be ACTUALLY fixed now, thanks for your patience. <3