-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Native arguably does a resolve.alias equivalent a la webpack now #46
Comments
@pcowgill i haven't experimented with it myself, but seems promising |
@mvayngrib Cool, thanks for getting back to me! Would you like to experiment with it before accepting a PR that modifies this section in the |
@pcowgill that would great, do u have an example repo? |
I installed react-native-crypto and react-native-randombytes:
I skipped the linking of randombytes due to the autolinking feature of RN and added the extraNodeModules section like you suggested, @pcowgill
Now i get the following error when trying to start the metro bundler:
Any idea what I'm doing wrong? I'm running [email protected]. Thank you! |
I can confirm that extraNodeModules does the trick without any additional hacks:
resolver: {
extraNodeModules: {
crypto: path.resolve(__dirname, 'extra_modules/crypto')
},
},
import { randomBytes } from 'react-native-randombytes';
exports.getRandomValues = function getRandomValues(arr) {
let orig = arr;
if (arr.byteLength !== arr.length) {
// Get access to the underlying raw bytes
arr = new Uint8Array(arr.buffer);
}
const bytes = randomBytes(arr.length);
for (var i = 0; i < bytes.length; i++) {
arr[i] = bytes[i];
}
return orig;
};
exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = randomBytes;
|
Thanks @mobitar! |
@mvayngrib Is the example above enough evidence to justify updating the README? Thanks! |
@mobitar -- this doesn't work. You still end up with an error: and creates a require loop: Is this really your solution? can you provide more information? |
@mvayngrib - I had already run |
@ortonomy did u reinstall the app from xcode / react-native run-ios after that? |
@mvayngrib -- yes I did. I found a way to make this work without the need for @mobitar's complex solution. See here: philikon/ReactNativify#4 (comment)
is enough and that's it, it works in RN
Suggest adding this to the README.md as the defacto way of aliasing/polyfilling crypto core in RN |
@ortonomy do u have an example repo for the usage? I just tried the above and i get:
|
I have switched from rn-nodeify to https://github.com/parshap/node-libs-react-native for easier setup |
@mvayngrib -- sorry it took me a bit to get round to this. Yes, I should have been more explicit. The method I used is good enough to get the node |
In the
README
, it says that "react-native doesn't currently have aresolve.alias
a la webpack".Would you say that the
extraNodeModules
setting inmetro.config.js
counts as similar enough feature that achieves what you need?(Source)
The text was updated successfully, but these errors were encountered: