skip to content
Andrei Calazans

How to override a Node.js module with React Native's Metro config

/ 1 min read

I’ve had to figure this out twice now, so I thought I would document it.

When using React Native, How can I tell Metro to override a Node.js module with my own implementation?

Perhaps you are importing some Node JS module in your React Native app that relies on require('os') for instance.

error: Error: Unable to resolve module os from REDACTED.js: os could not be found within the project or in these directories:

You can easily tell Metro server to override a module using extraNodeModules:

// metro.config.js

module.exports = {
  resolver: {
    extraNodeModules: {
      fs: path.resolve(__dirname, "path/to/custom/fs.js"),
    },
  },
};