Home > Net >  Can I change a component I downloaded in react-native project from node_modules?
Can I change a component I downloaded in react-native project from node_modules?

Time:02-10

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!

CodePudding user response:

npm uninstall packName
npm install packageName

then start your project

Make sure server is off by the time you are running this command.

if it does not work reset-cache try starting it with npm start -- --reset-cache
expo r -c ///if u are using expo

CodePudding user response:

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.

  • Related