bnoordhuis / node-buffertools

working with node.js buffers made easy
ISC License
205 stars 35 forks source link

Cannot find module ''./build/Debug/buffertools.node' on windows electron #71

Closed christianbirg closed 8 years ago

christianbirg commented 8 years ago

I use pcsclite for scanning chip cards (buffertools is a node_module of them) in my electron app. on mac osx it works fine but when i start the same app on windows (win7) it raises an error

Uncaught Error: Cannot find module ''./build/Debug/buffertools.node'

The problem is that he cannot find ./build/Release/buffertools.node and he run the catch block. But the ./build/Release/buffertools.node is there.

Someone got an idea, is that an electron bug or from buffertools? Someon has an work around?

bnoordhuis commented 8 years ago

What happens when you require('./node_modules/buffertools/build/Release/buffertools.node')? I speculate you get an error complaining it's built for the wrong node version or the wrong architecture?

christianbirg commented 8 years ago

He also runs in the catch block.

this is my structure

- app
  - node_modules
    - buffertools
    - electron-prebuilt
    - pcsclite
    - ...
  - index.html
  - main.js
  - package.json

that is my package json

{
  "name": "application",
  "version": "0.1.0",
  "main": "main.js",
  "dependencies": {
     "angular": "1.4.7",
     "angular-ui-router": "0.2.15",
     "babel": "5.8.29",
     "buffertools": "2.1.3",
     "electron-prebuilt": "0.34.0",
     "electron-reload": "0.2.0",
     "jquery": "2.1.4",
     "pcsclite": "0.4.4"
   }
}

on my development maschine (mac osx) it works perfectly only on fucking windows it appears this error

bnoordhuis commented 8 years ago

He also runs in the catch block.

I think you misunderstood my suggestion. I'm asking you to require the .node file directly. Try this from the command line and post the output:

$ node -p 'require("./node_modules/buffertools/build/Release/buffertools.node")'
christianbirg commented 8 years ago

I can only run this script on my development maschine i think and thats the output

$ node -p 'require("./node_modules/buffertools/build/Release/buffertools.node")'

{ clear: [Function: clear],
 compare: [Function: compare],
 concat: [Function: concat],
 equals: [Function: equals],
 fill: [Function: fill],
 fromHex: [Function: fromHex],
 indexOf: [Function: indexOf],
 reverse: [Function: reverse],
toHex: [Function: toHex] }

I hope this is what you mean. But like i said, on my development maschine it works like expected. I dont know how i can run a node command without installing nodejs (there ist only a node runtime (ndoe.dll) in the folder.

christianbirg commented 8 years ago

Update: the try of resolving ./build/Realease/buffertools.node throws following exception

    Error: %1 is not a valid Win32 application.
    (…)

C:\Users\IEUser\Desktop\RocketLicence-win32-ia32\resources\app\node_modules\buffertools\build\Release\buffertools.node
    at Error (native)
    at Object.module.(anonymous function) (ATOM_SHELL_ASAR.js:137:20)
    at Object.module.(anonymous function) [as .node] (ATOM_SHELL_ASAR.js:137:20)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (C:\Users\IEUser\Desktop\RocketLicence-win32-ia32\resources\app\node_modules\buffertools\buffertools.js:24:20)
    at Module._compile (module.js:434:26)
    at Module._extensions..js (module.js:452:10)
bnoordhuis commented 8 years ago

Looks like you're trying to load a 64 bits buffertools.node into a 32 bits run-time. Run node-gyp rebuild on the target machine.

christianbirg commented 8 years ago

i have compiled it on a windows 32bit system and it works as a stand alone version, but in combination with electron it doesnt work. Now it is not the problem of this module, but maybe you have a solution for this?

bnoordhuis commented 8 years ago

You probably need to tell node-gyp where to find the electron headers / sources:

$ node-gyp --nodedir <path> rebuild
# or
$ npm install --nodedir <path> buffertools
christianbirg commented 8 years ago

Ah okay thanks now i understand. Thats not the problem of your library but the problem of pscslite, it only works with node < 4, so and the electron verison is 0.34.2. I have run following commands

npm config set disturl=https://atom.io/download/atom-shell
npm config set target=0.34.2
npm config set arch= ia32

npm install buffertools
npm install pcsclite

Now i automate this build :) Thank you very much

bnoordhuis commented 8 years ago

No problem, glad to hear it's working now. I'll go ahead and close the issue.