'Can I change a component I downloaded in react-native project from node_modules?

I want to use a kinda outdated module react-native-numbers-please (last update 2 years ago), but it doesn't work. I think it's because it uses a Picker from react-native. I've changed that in the module's NumbersPlease.tsx which is the main file from which the component is exported.

So I've updated it to use Picker from @react-native-picker/picker as react suggested in a warning message, but I don't think its changed anything since I still get the exact same warning (Picker has been extracted from react-native core and will be removed in a future release...).

I've tried restarting the npm server, but It hasn't changed anything.

Is there something else I need to do for react-native to recognize that I've changed the module, or does it just simply not work?

Thanks in advance!



Solution 1:[1]

You can start editing it inside node_modules folder and then patching the package. Then you need to run the following command to patch the package:

npm install -g patch-package
patch-package <module name>

This will create a folder at the root of the project called patches. Then in your package.json file under scripts add the following script:

"scripts": {
    ....
   "postinstall": "patch-package"
}

From now on, when you run install, it will also apply patches on original files.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matin Zadeh Dolatabad