Comments (9)
As a simple fix, based on some advice in an SO thread, I just placed the module names in variables, to force RN to evaluate the require's dynamically. I had some other unrelated changes on my fix branch, so having a hard time generating a clean PR, but the relevant commit is here: 8b8b715
from rn-nodeify.
@jd20 interesting, does that trick work with earlier versions of RN? I remember having some issue with dynamic requires on some version around 0.40-0.42...but don't remember what it was :)
another option would be to move the part inside the if
to the react-native-crypto library, and do one dynamic require here, a la:
if (require('./package.json').dependencies['react-native-crypto']) {
const crypto = 'react-native-crypto'
require(crypto)
}
maybe that would be cleaner? Then we wouldn't need dynamic requires all over the crypto piece
from rn-nodeify.
I think the dynamic require behavior changed around 0.40, but this trick shouldn't affect the behavior on older versions of RN.
So you're saying it's safe to move everything crypto-related in shim.js directly to react-native-crypto? I can take a stab at that.
from rn-nodeify.
i think so, but let me know how it turns out :)
from rn-nodeify.
Do you know the background on why browserify-sign is required? I seem to be able to do basic crypto stuff OK without requiring it, so having a hard time coming up with sample code to check if it's integrated correctly. Also, I needed to disable the crypto = window.crypto
, this seems to cause problems because it sets global crypto to an empty shim, instead of react-native-crypto. Likewise, defining crypto.getRandomValues doesn't hurt anything, but seems unnecessary since node doesn't have it, so I'm wondering if there's a reason we want to keep that in shim.js?
Also, more minor thing, but seems we might want to add a note to the README to run react-native link
after installing certain packages, since some like react-native-randombytes require it (took me a while to realize I needed to run it).
from rn-nodeify.
the browserify-sign bit was for one of my crypto projects. It doesn't actually require browserify-sign itself, it just adds an alias in the browserify-sign/algos section.
the rest of the crypto section is needed for modules that interpret their environment and decide that they're in the browser (take a look at brorand/index.js, which used to check explicitly for the window
object). Once they decide they're in the browser, they want getRandomValues :) The problem with tricking them into thinking they're in Node.js is that then they assume they access to some synchronous apis - e.g. fs.readFileSync, etc.
about the react-native link
bit, you're absolutely right, add it please!
from rn-nodeify.
I see, unfortunate that it's so messy :) I was confused at first why we'd want the node modules to think they were in the browser, but makes sense now. Will keep seeing what I can do with this.
from rn-nodeify.
Ok, submitted #54 for review. The react-native-crypto PR has to be merged first though, so please review that one first. I did some local testing (with both the updated react-native-crypto and rn-nodeify), using the sample randomBytes code in the README, and the getRandomValues() sample here: https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues. If using window.crypto.getRandomValues(), you do need to import 'crypto' first, which seems reasonable to me.
from rn-nodeify.
resolved with #54 and react-native-crypto#19
from rn-nodeify.
Related Issues (20)
- iOS Build is failing (duplicate symbols for architecture x86_64) HOT 6
- very awesome and useful project HOT 2
- shim.js issue on IOS HOT 2
- Security issues
- Request: Add ffjavascript support
- what is shim ?
- error Couldn't find the binary git.
- failed to parse package.json on windows HOT 3
- Nodify
- Cannot read property 'call' of undefined when calling createHmac function from crypto
- Tradle HOT 1
- shim for react-native-tls HOT 1
- modules broken after single package install HOT 4
- prevent hacking specific module
- Async_hooks HOT 2
- ypto
- Cannot build IOS bundle in production mode HOT 1
- Specific Module Installation Fails with --hack Flag HOT 1
- https module doesn't seems to be working properly HOT 4
- Strange error occurred
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rn-nodeify.