Search code examples
javascriptnode.jsreact-nativewebpackpolyfills

Use polyfills of Node.js built-in modules in React-Native


Some Node.js packages I'd like to use in a React-Native app have dependencies on Node.js' built-in modules like url, http and crypto. These packages are designed to be packaged with Webpack, and take advantage of Webpack's polyfills.

I've added the required polyfills to my root package.json file but I'm still seeing errors like Unable to resolve module 'crypto' in my app.

How do I tell the React-Native packager to use polyfills instead of trying to load the built-in Node.js modules?


Solution

  • For all those interested the best solution I've found is to use the mvayngrib/rn-nodeify Node.js package, which is a hack to allow react-native projects to use node core modules, and npm modules that use them.