nativescript-nodeify
nativescript-nodeify copied to clipboard
crypto-browserify shim is not usable
I would like to use the crypto-browserify module in my code, which should theoretically be possible as this module is fully supported in the browser. Unfortunately, upon loading my app I receive the following error:
System.err: ReferenceError: process is not defined
System.err: File: "file:///data/data/com.myapp/files/app/tns_modules/readable-stream/readable.js, line: 2, column: 4
I have done a bit of investigative work on this. Here is the chain of imports that lead to this error:
- My app:
- imports
crypto-browserify- imports
create-hash- imports
ripemd160- imports
hash-base- imports
stream-> converted tostream-browserify- imports
readable-stream
- imports
- imports
- imports
- imports
- imports
- imports
readable-stream defines a browser field in its package.json:
"browser": {
"util": false,
"./readable.js": "./readable-browser.js",
"./writable.js": "./writable-browser.js",
"./duplex.js": "./duplex-browser.js",
"./lib/internal/streams/stream.js": "./lib/internal/streams/stream-browser.js"
},
However, it would seem that the nativescript-nodeify library is ignoring this and falling back to the node.js file, which then fails due to the missing process global.
I found this line in the patch script: https://github.com/EddyVerbruggen/nativescript-nodeify/blob/97df5cc31c2104b698522c45e688badffe5b2d25/patch-npm-packages.js#L73
If I'm reading the code correctly, this script is unable to handle a browser field that is an object. Is that correct?
As I read it, the script handles browser as an object just fine, but in readable-stream main is "readable.js" but the key in browser-object is "./readable.js".