Nw.js: nodejs app works fine when starting with node, but fails when starting from index.html in nwjs

Created on 9 Dec 2016  ยท  5Comments  ยท  Source: nwjs/nw.js

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)

Most helpful comment

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

rm -rf node_modules
npm cache clean
npm install

All 5 comments

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

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)

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

rm -rf node_modules
npm cache clean
npm install

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

[email protected] 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: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

/root/.npm/_logs/2018-09-13T08_56_41_795Z-debug.log:
2411 silly install [email protected]
2412 info lifecycle [email protected]~install: [email protected]
2413 verbose lifecycle [email protected]~install: unsafe-perm in lifecycle true
2414 verbose lifecycle [email protected]~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 [email protected]~install: CWD: /volume1/git/node-ffmpeg-mpegts-proxy/node_modules/sleep
2416 silly lifecycle [email protected]~install: Args: [ '-c', 'node-gyp rebuild' ]
2417 silly lifecycle [email protected]~install: Returned: code: 1 signal: null
2418 info lifecycle [email protected]~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 [email protected]
2420 silly saveTree โ”œโ”€โ”ฌ [email protected]
...
2420 silly saveTree โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”œโ”€โ”ฌ [email protected]
2420 silly saveTree โ”‚ โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”‚ โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”‚ โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”‚ โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”‚ โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”‚ โ”œโ”€โ”€ [email protected]
2420 silly saveTree โ”‚ โ””โ”€โ”€ [email protected]
2420 silly saveTree โ””โ”€โ”€ [email protected]
2421 warn optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
2422 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: 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: [email protected] 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 [email protected]
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 [email protected] install: node-gyp rebuild
2433 error Exit status 1
2434 error Failed at the [email protected] install script.
2434 error This is probably not a problem with npm. There is likely additional logging output above.
2435 verbose exit [ 1, true ]

Was this page helpful?
0 / 5 - 0 ratings