Upgraded to v46, APK crashes, but works on Expo Go. How to fix ViewPropTypes error, is patching React Native allowed?

I’ve recently updated to Expo v46, and it’s working smoothly on Expo Go. However, the APK and iOS simulator build of the same app crashes at the splash screen.

I’ve done an adb logcat and found this error regarding ViewPropTypes:

ReactNativeJS: Invariant Violation: ViewPropTypes 
has been removed from React Native. Migrate to 
ViewPropTypes exported from 'deprecated-react-native-prop-types'.
  1. Why doesn’t this error appear on Expo Go?
  2. I’ve searched through all my code and node_modules and have replaced all usages of ViewPropTypes that import from react-native. I did not touch those in react-native or those that import from paths like 'react-native/Libraries/Components/View/ViewPropTypes';
  3. Since I still get the error even though I’ve fixed the usages of it, I tried to patch React Native using this: Invariant Violation: ViewPropTypes has been removed from React Native. · Issue #33734 · facebook/react-native · GitHub, but I end up with a prebuild error that does not happen without the patch:
[stderr] The android project is malformed, project files will be cleared and reinitialized.
- Clearing android
✔ Cleared android code
- Creating native project directories (./ios and ./android) and updating .gitignore
✔ Created native project | gitignore skipped
- Adding Metro bundler config
› Metro skipped: Project metro.config.js does not match prebuild template.
› Ensure the project uses @expo/metro-config.
  Learn more: https://docs.expo.dev/guides/customizing-metro
- Updating your package.json scripts, dependencies, and main file
✔ Updated package.json and added index.js entry point for iOS and Android
- Config syncing
[stderr] Using node to generate images. This is much slower than using native packages.
[stderr] › Optionally you can stop the process and try again after successfully running `npm install -g sharp-cli`.
- Config syncing
[stderr] » android: sentry-expo: Could not find react.gradle script in android/app/build.gradle. Please open a bug report at https://github.com/expo/sentry-expo.
- Config syncing
✔ Config synced
Running "npm install" in the root dir of your repository 
> mycompany.myappname@4.50.1 postinstall
> ./npm-postinstall.sh
patching file node_modules/react-native/index.js
Reversed (or previously applied) patch detected!  Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file node_modules/react-native/index.js.rej
[stderr] npm
[stderr] ERR! code 1
[stderr] npm
[stderr] ERR! path /home/expo/workingdir/build
[stderr] npm ERR!
[stderr] command failed
[stderr] npm ERR! command sh -c ./npm-postinstall.sh
[stderr] npm ERR! A complete log of this run can be found in:
[stderr] npm ERR!     /home/expo/.npm/_logs/2022-08-24T11_10_00_715Z-debug.log
npm exited with non-zero code: 1

npm-postinstall.sh is just 1 line:

patch -p1 < RN-deprecated-proptypes.patch -N

Are we not allowed to patch React Native? How would I get around this ViewPropTypes issue?

  • you should use patch-package to patch npm dependencies. i don’t know why your patch failed, we don’t do anything to prevent that.
  • it’s impossible to know why this error might not show up in expo go without looking at the project. did you try running npx expo start --no-dev --minify to more closely re-create the production environment?

more tips in Troubleshooting build errors and crashes - Expo Documentation

I tried npx expo start --no-dev --minify and it worked with no issues as well.

I’ll try out patch-package. I didn’t try it since I figured it does the same thing as a manual postinstall script anyway. I’ll let you know if it works

Everything is working fine after using patch-package. How strange :thinking:

Anyway, thanks for the help!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.