nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.26k stars 3.89k forks source link

nodejs app works fine when starting with node, but fails when starting from index.html in nwjs #5538

Closed AlexKotov closed 7 years ago

AlexKotov commented 7 years ago

I'm using next technologies in my app: nodejs v7.2.1 nwjs v0.19.0 node in nwjs v7.2.0 Windows 10 Pro x64 npm ffi npm ref npm ref-array npm sleep MasterRD.dll

Code, that fails:

var CARDREADER = (function() {
    window.CARDREADER = CARDREADER;

    var ffi = require('../cardreader/node_modules/ffi'),
        ref = require('../cardreader/node_modules/ref'),
        ArrayType = require('../cardreader/node_modules/ref-array'),
        Sleep = require('../cardreader/node_modules/sleep'),
        CharArray = ArrayType(ref.types.char),
        chatPtr = ref.refType('char'),
        intPtr = ref.refType('int32'),
        BUFFER_LENGTH = 20,
        stateAvailabilityCard = false,
        statusConnected = 1;

    RFIDfunctions = ffi.Library('../cardreader/MasterRD', {
        'rf_init_com': ['int', ['int', 'int']],//Port, bound rate
        'rf_light': ['int', ['int', 'int']],//Device ID, 0 = off 1 = red 2 = green 3 = yellow
        'rf_beep': ['int', ['int', 'int']],//Device ID, beep time msec
        'rf_antenna_sta': ['int', ['int', 'int']],//Device ID, model = 0: turn off RF transmittal model = 1: turn on RF transmittal
        'rf_init_type': ['int', ['int', 'int']],//Device ID, type = 'A': set SL500 into ISO14443A modetype = 'B': set ISO14443B modetype = 'r': set AT88RF020 card modetype = '1': set ISO15693 mode
        'rf_request': ['int', ['int', 'int', chatPtr]],// Device ID, model: [IN] REQ MODE, pTagType: [OUT] response data, chip type code
        'rf_anticoll': ['int', ['int', 'int', CharArray, chatPtr]],//Device ID,  bcnt: [IN] must be 4, pSnr: [OUT] response data from card, unique serial number pLen: [OUT] length of response data
        'rf_select': ['int', ['int', CharArray, 'int', chatPtr]],//Device ID, pSnr: [IN] card unique serial number, snrLen: [IN] length of pSnr, pSize: [OUT] response data from card, capacity code
        'rf_M1_authentication2': ['int', ['int', 'int', 'int', 'pointer']],//Device ID, model: [IN] key validate mode, block: [IN] block absolute address, pKey: [IN] 6 bytes password
        'rf_M1_readval': ['int', ['int', 'int', intPtr]], //Device ID, block: [IN] block absolute address, pValue: [OUT] response value at HEX format, low byte in former
        'rf_M1_initval': ['int', ['int', 'int', 'int32']], //Device ID, block: [IN] block absolute address, pValue: [IN] initialize purse value at HEX format, low byte in former
        'rf_M1_read': ['int', ['int', 'int', CharArray, chatPtr]],//Device ID, block: [IN] block absolute address, pData: [OUT] response data from card, pLen: [OUT] length of response data
        'rf_M1_write': ['int', ['int', 'int', 'pointer']], //Device ID, block: [IN] block absolute address, pData: [IN] written data, 16 bytes
        'rf_ClosePort': ['int', []]
    });

    return {
    };
})();
Uncaught Error: A dynamic link library (DLL) initialization routine failed.
\\?\C:\Users\someUser\Desktop\dev\nwjs\projects\my-betshop\cardreader\node_modules\ref\build\Release\binding.node
    at Object.Module._extensions..node (module.js:640:18)
    at Module.load (module.js:512:32)
    at tryModuleLoad (module.js:471:12)
    at Function.Module._load (module.js:463:3)
    at Module.require (module.js:522:17)
    at require (internal/module.js:20:19)
    at bindings (C:\Users\someUser\Desktop\dev\nwjs\projects\my-betshop\cardreader\node_modules\bindings\bindings.js:76:44)
    at Object.<anonymous> (C:\Users\someUser\Desktop\dev\nwjs\projects\my-betshop\cardreader\node_modules\ref\lib\ref.js:5:47)
    at Module._compile (module.js:595:32)
    at Object.Module._extensions..js (module.js:610:10)
rogerwang commented 7 years ago

Looks like that the native modules need rebuilding, see http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/

AlexKotov commented 7 years ago

Oh, thanx. It works. But i've got new issue:

Uncaught Error: Cannot find module './build/Release/node_sleep.node'
    at Function.Module._resolveFilename (module.js:494:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:522:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (C:\Users\someUser\Desktop\dev\nwjs\projects\my-betshop\cardreader\node_modules\sleep\index.js:2:18)
    at Module._compile (module.js:595:32)
    at Object.Module._extensions..js (module.js:610:10)
    at Module.load (module.js:512:32)
    at tryModuleLoad (module.js:471:12)
    at Function.Module._load (module.js:463:3)
AlexKotov commented 7 years ago

Solved " Uncaught Error: Cannot find module './build/Release/node_sleep.node' ":

rm -rf node_modules npm cache clean npm install

findingneo17 commented 5 years ago

Tried the above: ash-4.3# rm -rf node_modules/ ash-4.3# npm cache clean --force npm WARN using --force I sure hope you know what you are doing. ash-4.3# npm install gyp WARN EACCES user "root" does not have permission to access the dev dir "/volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep/.node-gyp/8.9.4" gyp WARN EACCES attempting to reinstall using temporary dev dir "/volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep/.node-gyp" ^C

Tried the above with --unsafe-perm option to npm install: ash-4.3# rm -rf node_modules/ ash-4.3# npm cache clean --force npm WARN using --force I sure hope you know what you are doing. ash-4.3# npm install --unsafe-perm

sleep@4.0.0 install /volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep node-gyp rebuild

gyp ERR! build error gyp ERR! stack Error: not found: make gyp ERR! stack at getNotFoundError (/usr/local/lib/node_modules/npm/node_modules/which/which.js:13:12) gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:19) gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29) gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16 gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/index.js:42:5 gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/mode.js:8:5 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:152:21) gyp ERR! System Linux 4.4.59+ gyp ERR! command "/volume1/@appstore/Node.js_v8/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep gyp ERR! node -v v8.9.4 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! sleep@4.0.0 install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the sleep@4.0.0 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-09-13T08_56_41_795Z-debug.log

findingneo17 commented 5 years ago

/root/.npm/_logs/2018-09-13T08_56_41_795Z-debug.log: 2411 silly install sleep@4.0.0 2412 info lifecycle sleep@4.0.0~install: sleep@4.0.0 2413 verbose lifecycle sleep@4.0.0~install: unsafe-perm in lifecycle true 2414 verbose lifecycle sleep@4.0.0~install: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep/node_modules/.bin:/volume1/git/node-ffmpeg-mpegts-proxy/node_modules/.bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin:/var/services/homes/Enoch/bin:.:/root/bin:. 2415 verbose lifecycle sleep@4.0.0~install: CWD: /volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep 2416 silly lifecycle sleep@4.0.0~install: Args: [ '-c', 'node-gyp rebuild' ] 2417 silly lifecycle sleep@4.0.0~install: Returned: code: 1 signal: null 2418 info lifecycle sleep@4.0.0~install: Failed to exec install script 2419 verbose unlock done using /root/.npm/_locks/staging-88f7d7341732df16.lock for /volume1/git/node-ffmpeg-mpegts-proxy/node_modules/.staging 2420 silly saveTree node-ffmpeg-mpegts-proxy@0.8.0 2420 silly saveTree ├─┬ chokidar@1.7.0 ... 2420 silly saveTree ├── sleep@4.0.0 2420 silly saveTree ├─┬ winston@0.8.3 2420 silly saveTree │ ├── async@0.2.10 2420 silly saveTree │ ├── colors@0.6.2 2420 silly saveTree │ ├── cycle@1.0.3 2420 silly saveTree │ ├── eyes@0.1.8 2420 silly saveTree │ ├── isstream@0.1.2 2420 silly saveTree │ ├── pkginfo@0.3.1 2420 silly saveTree │ └── stack-trace@0.0.10 2420 silly saveTree └── yargs@1.3.3 2421 warn optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents): 2422 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) 2423 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS: darwin 2423 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch: any 2423 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS: linux 2423 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64 2424 verbose stack Error: sleep@4.0.0 install: node-gyp rebuild 2424 verbose stack Exit status 1 2424 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16) 2424 verbose stack at emitTwo (events.js:126:13) 2424 verbose stack at EventEmitter.emit (events.js:214:7) 2424 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 2424 verbose stack at emitTwo (events.js:126:13) 2424 verbose stack at ChildProcess.emit (events.js:214:7) 2424 verbose stack at maybeClose (internal/child_process.js:925:16) 2424 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) 2425 verbose pkgid sleep@4.0.0 2426 verbose cwd /volume1/git/node-ffmpeg-mpegts-proxy 2427 verbose Linux 4.4.59+ 2428 verbose argv "/volume1/@appstore/Node.js_v8/usr/local/bin/node" "/usr/local/bin/npm" "install" "--unsafe-perm" 2429 verbose node v8.9.4 2430 verbose npm v5.6.0 2431 error code ELIFECYCLE 2432 error errno 1 2433 error sleep@4.0.0 install: node-gyp rebuild 2433 error Exit status 1 2434 error Failed at the sleep@4.0.0 install script. 2434 error This is probably not a problem with npm. There is likely additional logging output above. 2435 verbose exit [ 1, true ]