react-native: Invariant Violation: ViewPropTypes has been removed from React Native.
Description
Recently updated react to 18 version, and since that I’m not able to build my app. At first I’ve received “TypeError: dispatcher.useSyncExternalStore is not a function.” and fixed by updating react-native to “0.69.0-rc.0” version. But now having these errors:
`ERROR Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
Version
0.69.0-rc.0
Output of npx react-native info
OS: Linux 5.13 Ubuntu 20.04.4 LTS (Focal Fossa) CPU: (4) x64 Intel® Core™ i5-6500 CPU @ 3.20GHz Memory: 1.75 GB / 15.50 GB Shell: 5.0.17 - /bin/bash Binaries: Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node Yarn: Not Found npm: 8.7.0 - ~/.nvm/versions/node/v12.14.1/bin/npm Watchman: Not Found SDKs: Android SDK: Not Found IDEs: Android Studio: Not Found Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: ^0.69.0-rc.0 => 0.69.0-rc.0 npmGlobalPackages: react-native: Not Found
Steps to reproduce
react-native run-android
Snack, code example, screenshot, or link to a repository
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 21
- Comments: 80 (6 by maintainers)
Links to this issue
Commits related to this issue
- react-native 0.69.1; react-native-screens 3.14.1; esperando por fix de https://github.com/facebook/react-native/issues/33734 — committed to jacargentina/iResucito by jacargentina 2 years ago
- 提交引入轮播图依赖包react-native-snap-carousel,以及有可能出现的viewPropsTypes问题,解决地址https://github.com/facebook/react-native/issues/33734 — committed to lmJoe/ximalayaProjectDemo by deleted user 2 years ago
- fix: add deprecated-react-native-prop-types added a packaged to provite support for ViewPropTypes which was deprecated in React 18. See here: https://github.com/facebook/react-native/issues/33734. Th... — committed to Living-Snow-Project/LivingSnowProject by tccw 2 years ago
it’s really unprofessional when someone just decides to break up the whole react-native community because he decided to deprecate a functionality that he doesn’t like
Same issue here after upgrading to 0.69, there are a lot of external libraries still using ViewPropTypes. Perhaps an unpopular opinion, but maybe it’s too early to deprecate ViewPropTypes completely?
Nice discussion going on here, inspired me to implement a workaround in our app using patch-package.
Install patch-package into your project, as per the instructions.
Install deprecated-react-native-prop-types by running
npm install deprecated-react-native-prop-types
oryarn add deprecated-react-native-prop-types
.The invariant seems to be enforced in node_modules/react-native/index.js, starting at line 436:
So, change these lines to return the corresponding Prop Types from deprecated-react-native-prop-types instead:
Save and run
npx patch-package react-native
to save the patch.Rebuild and the app should launch.
Only thing to keep in mind is that this patch will need to be reapplied with every upgrade to react-native, or until the libraries in question are updated to import from deprecated-react-native-prop-types instead.
Hey all, as mentioned in https://github.com/facebook/react-native/issues/33557, back in 2018 we started to remove PropTypes from React Native. Last year, in 0.68 we introduced a deprecation warning which notified users that the change is coming, and in 0.69 we removed the PropTypes entirely…
Because of this it is not recommended to ignore the warning as some comments above suggest (I’ve hidden those comments as outdated to prevent confusion). If you ignore the warning then in a future version you will hit issues like https://github.com/facebook/react-native/issues/33734 when we fully remove the deprecated code.
It’s also not recommend to use patch-package on the React Native file because this will only mask the issue.
Recommended Fix
The recommended fix is to switch from PropTypes to a type system like TypeScript.
If you need to continue using PropTypes, the fix is to find the code that is using PropTypes and switch the import from:
to:
Sometimes, a library you depend on may be using the PropTypes. In that case, it’s recommended to submit an issue or PR to the library and/or update to the latest version. In extreme cases (like the library you’re using is unmaintained) you may need to fork the library, or use patch-package for that library itself to replace the types until it’s fixed upstream.
This is a big issue for anyone that wants to upgrade react-native. It will be great if we can find a workaround, as going manually and looking for the hundreds of places in which a 3rd party package requires a correction, and patching the correction, is just not feasible.
Any suggestion how to know which dependencies were affected by this issue?
Same here after bumping up to “0.69.0”
Still an issue in
0.69.1
. see my comments #33557There is no easy fix for this. It’s a problem in react-native library. How can this be closed? You have to make a lot of weird shady changes to your code so you can run it.
Hi,
this issue can be solved using babel-plugin-module-resolver
you can alias react-native module, with example like bellow
saved the code to javascript file to use in babel config, and you need to set up a proper resolver for allowlist/blocklist certain library that can result in a conflicting file. for the example see bellow,
Created a file
rn-polyfill-depricated-proptypes.js
, and imported at top of index.js. Solved the issue for meyou may also change the get function to return from
deprecated-react-native-prop-types
For those who don’t use hermes, you can solve the _reactNative.textInput.propTypes.style error using the method of @mukti107 and @psycheangel only that I have added a new option that has neither of the 2 forms.
They must create a file in the root with the name they like in my case rn-polyfill-depricated-proptypes.js and they will place it in the index.js of the project at the top like this
after this add the following to the created file
` /** *File: rn-polyfill-depricated-proptypes.js **/
const StandardModule = require(‘react-native’); const dpProps = require(‘deprecated-react-native-prop-types’);
const txtImputProx = new Proxy(StandardModule.TextInput, { get(obj, prop) { if (prop === ‘propTypes’) return dpProps.TextInputPropTypes; return Reflect.get(…arguments); }, });
Object.defineProperty(StandardModule, ‘ColorPropType’, { configurable: true, get() { return dpProps.ColorPropType; }, });
Object.defineProperty(StandardModule, ‘EdgeInsetsPropType’, { configurable: true, get() { return dpProps.EdgeInsetsPropType; }, });
Object.defineProperty(StandardModule, ‘PointPropType’, { configurable: true, get() { return dpProps.PointPropType; }, });
Object.defineProperty(StandardModule, ‘ViewPropTypes’, { configurable: true, get() { return dpProps.ViewPropTypes; }, });
Object.defineProperty(StandardModule, ‘TextPropTypes’, { configurable: true, get() { return dpProps.TextPropTypes; }, });
Object.defineProperty(StandardModule, ‘TextInputPropTypes’, { configurable: true, get() { return dpProps.TextInputPropTypes; }, });
Object.defineProperty(StandardModule, ‘TextInput’, { configurable: true, get() { // return dpProps.TextInputPropTypes; return txtImputProx; }, });
// Object.defineProperty(StandardModule, ‘TextStylePropTypes’, { // configurable: true, // get() { // return dpProps.TextInputPropTypes; // }, // });
// Object.defineProperty(StandardModule, ‘ImagePropTypes’, { // configurable: true, // get() { // return require(‘deprecated-react-native-prop-types/DeprecatedImagePropType’); // }, // });
// Object.defineProperty(StandardModule, ‘ImageStylePropTypes’, { // configurable: true, // get() { // return require(‘deprecated-react-native-prop-types/DeprecatedImageStylePropTypes’); // }, // });
// Object.defineProperty(StandardModule, ‘ViewStylePropTypes’, { // configurable: true, // get() { // return dpProps.ViewPropTypes; // }, // });
// console.log("StandardModule–> ", StandardModule.ColorPropType); `
This way it will work for them and the app will run perfectly, but in my case FETCH() doesn’t work for me, does anyone have an idea why fetech doesn’t work in react-native 69.4
very thankful.
I hope the contribution helps you.
Don’t forget to mention it must be inside a
patches
folder and you need thepatch-package
dependency for it to run automatically on everyyarn
/npm
install command.Here is the diff for @goguda’s solution. You can just paste this into a file called
react-native+0.69.3.patch
so you don’t have to copy the screenshot edits manually:Same problem, just downgrade and wait for someone to fix it
You’ll need to either convince the maintainer to fix it, or fork the dependency and fix it. There’s no other way to remove that error
Hi,
I use babel-plugin-module-resolver based on experience dealing with the same issue to ‘overrides’ certain native components inside the react-native package which not working in web implementation (react-native-web).
@ajp8164 Based on my setup of a project the resolver needs to be excluded from node_modules/react-native, because it will break the importing use inside the react-native package. you only need to replace other packages/project files besides the node_modules/react-native to use the resolver file when importing the react-native package.
@CCB-cerivera It would be nice if that polyfill module just implemented your solution.
It’s much simpler than using babel or any of the other solutions, and should work everywhere. Hopefully most dependencies will have this problem fixed soon, but your code could be a useful NPM package if you’re feeling ambitious.
Either way, it’s working well for me. Thanks!
no 😐
same issue here version 0.69.4
Have you resolved this problem, other than patching? I tried the patch option but it returns the following:
I have already done cd android && gradlew clean react-native start --reset-cache npm cache clean --force
and it keeps sending the same error.
I would like to use version 69.4 but I have many third party libraries that use propsType so it is not working.
I’ve been using this resolver solution for a while and it works very well. No intrusion.
Yes, I also had this problem with the Text props. In my case, if I’m not mistaken, it was because of
react-native-credit-card-input
, which is just way too old. I think the error contains the file where it happened. If so, I don’t think you should find a workaround to make the library work and, instead, look for a new one, updated more often.Try running
react-native start —reset-cache
and rebuilding.有什么好的解决办法么,我也遇到了,升级RN,从0.64到0.69.1会报这个错
I create a readme file in the GitHub example link
@CaptainJeff
I create an example GitHub repo using the standard init project, here is the link