-
Notifications
You must be signed in to change notification settings - Fork 23
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
Built-in alternative to babel-plugin-rewrite-require (extraNodeModules) #4
Comments
@parshap thanks for cc'ing me, hope to check it out very soon! |
Woah! I'll check it out for sure!
This is what the |
Hey @parshap I'm running react-native |
node-libs-browser doesn't include a "polyfill" for net. You'll have to include react-native-tcp. Also check out https://www.npmjs.com/package/node-libs-react-native |
Yo @parshap!
I'm not sure, I've also seen modules brought in via rn-cli.config.js trip over
|
The only thing that works for me right now is this .babelrc file. I deleted my
and
|
@wswoodruff: module.exports = {
extraNodeModules: {
...extraNodeModules,
net: require.resolve('react-native-tcp'),
},
}; |
@parshap I'm having trouble with your approach. Are you doing anything besides adding your
In the original file: |
…tatements with babel-plugin-rewrite-require as seen in: philikon/ReactNativify#4 (comment)
…tatements with babel-plugin-rewrite-require as seen in: philikon/ReactNativify#4 (comment)
…tatements with babel-plugin-rewrite-require as seen in: philikon/ReactNativify#4 (comment)
This commit installs packages that bip39 depends on that is not available in React Native. It then uses babel-plugin-rewrite-require to rewrite the requires for these dependencies to use the React Native versions instead. And last it exposes some global variables such as Buffer and process using globals.js. This solution is based on the idea of ReactNativify: https://github.com/philikon/ReactNativify But has been made much simpler thanks to this thread: philikon/ReactNativify#4
For people arriving in the future: To use this properly now you should edit your
|
@philikon Do you think this ^ alternative approach is worth documenting in the |
@parshap Would you consider updating your gist to say |
Updated, thanks! Can you clarify what you mean by the |
@parshap Thanks!! The author of Here is the feature itself: I don't think there's a way to make suggestions in the gist directly other than adding a comment, but my suggestion would be to remove this line: "not supporting ...since it does support that if you use the |
Does this work if crypto is required by a dependency of a dependency? For example, we use yarn workspaces and have a shared library. That library depends on |
Update
See this library for convenience: https://github.com/parshap/node-libs-react-native
And this gist for more details: https://gist.github.com/parshap/e3063d9bf6058041b34b26b7166fd6bd
Original post
The React Native Packager has a built-in option,
extraNodeModules
, which seems to act as a module alias mapping. I couldn't find much information about this option, but here's the PR where it was added: facebookarchive/node-haste#69. Here's myrn-cli.config.js
:And it seems to be working! I had to find this alternative approach because
babel-plugin-rewrite-require
was failing on a module with a dynamic require: readable-stream doesrequire('st'+'ream')
.This may be a better approach than using
babel-plugin-rewrite-require
because it doesn't need a customtransformer.js
or a static mapping in.babelrc
, and it seems to work on dynamic requires!@davidaurelio: Is this an appropriate use of the
extraNodeModules
option?/cc @mvayngrib
The text was updated successfully, but these errors were encountered: