-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web (react-native-web) will not support ViewPropTypes API it is upcoming release #1033
Comments
Just hit this problem on my upgrade to react-native-web 0.12 |
I have a PR for this, but it's still waiting for review :( #1089 |
@Inbal-Tish is that possible to incorporate @nathsimpson PR in? thx |
it seems that it was merged yesterday into the main branch, but error is showing in 1.280.0. Not clear if the fix made into npm release. |
@nathsimpson
If I am understanding this correctly, your update checks if ViewPropTypes is defined, and if it is not defined, it aliases to something else. However webpack or babel (we are using CRA toolchain with config overrides),
Are you somehow able to tell webpack to ignore the non-existing import? thank you in advance for any hints |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This is the solution: // agenda/index.js
import {Text, View, Dimensions, Animated, Platform} from 'react-native';
...
const viewPropTypes =
typeof document !== 'undefined' || Platform.OS === 'web'
? PropTypes.shape({style: PropTypes.object})
: require('react-native').ViewPropTypes || View.propTypes; We'd do the same in @nathsimpson I believe #1089 breaks react-native-web tree shaking by importing the whole package. I could submit a PR with a fix. In the meantime, I might rely on UpdateHere's what I did:
{
"scripts": {
"postinstall": "patch-package"
}
}
Put this in that file: diff --git a/node_modules/react-native-calendars/src/agenda/index.js b/node_modules/react-native-calendars/src/agenda/index.js
index 1f17071..7dd202f 100644
--- a/node_modules/react-native-calendars/src/agenda/index.js
+++ b/node_modules/react-native-calendars/src/agenda/index.js
@@ -1,5 +1,5 @@
import React, {Component} from 'react';
-import * as ReactNative from 'react-native';
+import {Text, View, Dimensions, Animated, Platform} from 'react-native';
import PropTypes from 'prop-types';
import XDate from 'xdate';
@@ -15,11 +15,10 @@ import {AGENDA_CALENDAR_KNOB} from '../testIDs';
const HEADER_HEIGHT = 104;
const KNOB_HEIGHT = 24;
//Fallback for react-native-web or when RN version is < 0.44
-const {Text, View, Dimensions, Animated, ViewPropTypes} = ReactNative;
const viewPropTypes =
- typeof document !== 'undefined'
+ typeof document !== 'undefined' || Platform.OS === 'web'
? PropTypes.shape({style: PropTypes.object})
- : ViewPropTypes || View.propTypes;
+ : require('react-native').ViewPropTypes || View.propTypes;
/**
* @description: Agenda component
diff --git a/node_modules/react-native-calendars/src/calendar/index.js b/node_modules/react-native-calendars/src/calendar/index.js
index 92d5bd5..815bc98 100644
--- a/node_modules/react-native-calendars/src/calendar/index.js
+++ b/node_modules/react-native-calendars/src/calendar/index.js
@@ -1,5 +1,5 @@
import React, {Component} from 'react';
-import * as ReactNative from 'react-native';
+import {Platform, View} from 'react-native';
import PropTypes from 'prop-types';
import XDate from 'xdate';
@@ -17,11 +17,10 @@ import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures';
import {SELECT_DATE_SLOT} from '../testIDs';
//Fallback for react-native-web or when RN version is < 0.44
-const {View, ViewPropTypes} = ReactNative;
const viewPropTypes =
- typeof document !== 'undefined'
+ typeof document !== 'undefined' || Platform.OS === 'web'
? PropTypes.shape({style: PropTypes.object})
- : ViewPropTypes || View.propTypes;
+ : require('react-native').ViewPropTypes || View.propTypes;
const EmptyArray = [];
/**
You should see this: |
That feeling when you're looking up this issue, and people are discussing a PR you made 😅 |
Apologies @vladp for not seeing your comments |
I left some comments on #1313, which should help solve the outstanding issues there. It would be awesome to have it merged. In the meantime, I'll probably have to make the changes on my local branch. Thanks to everyone helping on this! |
Here's my patch-web.sh script that i keep in a # needed by some libraries for react-native-web 12+ which no longer exports ViewPropTypes
if test -f "node_modules/react-native-web/dist/patched"; then
echo "react-native-web already patched!"
else
echo "Patching react-native-web propTypes"
echo '\n'"export const ViewPropTypes = { style: ()=>{} };" >> node_modules/react-native-web/dist/index.js
mkdir -p node_modules/react-native-web/dist/exports/ViewPropTypes
echo "" >> node_modules/react-native-web/dist/exports/ViewPropTypes/index.js
# patch Text default propTypes export:
echo '\n'"Text.propTypes = {
style: ()=>{}
}" >> node_modules/react-native-web/dist/exports/Text/index.js
#patch Image default propTypes export:
echo '\n'"Image.propTypes = {
style: ()=>{}
}" >> node_modules/react-native-web/dist/exports/Image/index.js
echo "patched" >> node_modules/react-native-web/dist/patched
fi |
Maybe we can just stop using ViewPropTypes? I've created a PR #1424 |
I choose remove all props-type, and it's work for me. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
it seems that there are no upstream fixes in this repo that will resolve this issue. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Description
React-native-calendars is a very portable package. Some folks, like us, have been using it on web browsers with React-native-web.
With React-native-web release 0.12 and above, RNW will remove ViewPropTypes export.
This API, unfortunately, is being used by this package, therefore, unless changes are made this will break the web-platform usage.
(tested with most recent release of react-native-calendars 1.221.0 and the upcoming release candidate for RNW -- 0.12.0-rc.1)
The text was updated successfully, but these errors were encountered: