Open RonAmihai opened 4 years ago
create web-postinstall-fix.sh
# https://github.com/necolas/react-native-web/issues/1537
# https://github.com/archriss/react-native-snap-carousel/issues/770
echo 'Fixing PropTypes issues'
if test -f node_modules/react-native-web/dist/exports/ViewPropTypes/index.js; then
echo "ViewPropTypes problem fixed already!"
else
mkdir node_modules/react-native-web/dist/exports/ViewPropTypes
touch node_modules/react-native-web/dist/exports/ViewPropTypes/index.js
echo 'var ViewPropTypes = { style: null }; export default ViewPropTypes;'>> node_modules/react-native-web/dist/exports/ViewPropTypes/index.js
echo "export { default as ViewPropTypes } from './exports/ViewPropTypes';">> node_modules/react-native-web/dist/index.js
fi
if grep -qs "Text.propTypes" node_modules/react-native-web/dist/exports/Text/index.js
then
echo "Text props types problem fixed already!"
else
echo 'Text.propTypes = {}'>> node_modules/react-native-web/dist/exports/Text/index.js
fi
in package.json
"scripts": {
"postinstall": "sh ./web-postinstall-fix.sh",
then after yarn install
problem will fixed
Version
Expected behaviour
Application using
react-native-router-flux
should render on web correctly (usingreact-native-web
v0.12+), without any errors.Actual behaviour
react-native-web
had removed support forViewPropTypes
since v0.12 (because Facebook has declared thePropTypes
API as deprecated and suggests Flow/Typescript instead).Because of that, any react-native library which use
ViewPropTypes
simply throws runtime error/s when running on web usingreact-native-web
v0.12+.In
react-native-router-flux
's case, the error is thrown inRouter.js
at the specified line: https://github.com/aksonov/react-native-router-flux/blob/b9377e3b39752cf19fa9f7d2c530543efd0be3db/src/Router.js#L135Because
ViewPropTypes
doesn't exist onreact-native-web
v0.12+, the following error is thrown:Steps to reproduce
expo-cli
react-native-web
is updated to latest version (or at least v0.12)yarn web
/expo start --web
Possible solution / Quick fix
The above error can be solve by removing any
ViewPropTypes
usage from the library, or by mockingViewPropTypes
functionality wheneverViewPropTypes
isundefined
.For example, the following fix has been solved the above error in
Router.js
(line 135) for my case:sceneStyle: ViewPropTypes ? ViewPropTypes.style : PropTypes.object
This fix at
Router.js
seems to makereact-native-router-flux
function well withreact-native-web
v0.12+, but I don't sure if there are any moreViewPropTypes
usage in the library.However, mocking any
ViewPropTypes
usage with relevantPropTypes
type will probably solve any issue like this