Skip to content
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

'ViewPropTypes' is not supported in 'react-native-web' v12.0 onwards #41

Closed
kkapilchoubisa opened this issue Feb 24, 2020 · 11 comments
Closed

Comments

@kkapilchoubisa
Copy link

Getting following error while running my app with react-native-web-swiper:

./node_modules/react-native-web-swiper/build/Badge.js
Attempted import error: 'ViewPropTypes' is not exported from 'react-native'.

My code is below:

    const carouselItems = carouselData.map((data, index)=>{
      return renderCarouselView(data, index);
    })
    return (
      <Swiper>
        { carouselItems }
      </Swiper>
    );
@kkapilchoubisa kkapilchoubisa changed the title Attempted import error: 'ViewPropTypes' is not exported from 'react-native' 'ViewPropTypes' is not supported in 'react-native-web' v12.0 onwards Feb 25, 2020
@kkapilchoubisa
Copy link
Author

I was trying to figure out the problem and I found that react-native-web version 12.0 and onwards do not support ViewPropType.

@dantenol
Copy link

Any updates on how to fix that?

@dantenol
Copy link

So, as the last issue reported, this package no longer works work with the latest react-native-web because ViewPropTypes is deprecated (more on the release note). The Controls, Swiper and Badge files used this method for validation of styles received as props.

The solution is pretty easy, basically use PropTypes.shape() for number, array or object.

Can i submit a PR for that?

@ozcanzaferayan
Copy link

I forked repo and fixed this issue:
https://github.com/ozcanzaferayan/react-native-web-swiper

@wkngau219
Copy link

Hi, any plan to merge ozcanzaferayan's fix and release?

@oxyii
Copy link
Collaborator

oxyii commented May 13, 2020

@ozcanzaferayan Thank you for your help. Changes from your fork already merged as diff.

@kei-ngau @dantenol @kkapilchoubisa Please try 2.1.1

@oxyii oxyii closed this as completed May 13, 2020
@oxyii
Copy link
Collaborator

oxyii commented May 13, 2020

@ozcanzaferayan Can you take this repo (and npm package) for maintaining? #42

@flyskywhy
Copy link

npm install --save-dev react-app-rewired

Create a config-overrides.js in your project root

// used by react-app-rewired

const webpack = require('webpack');
const path = require('path');

module.exports = {
  webpack: function (config, env) {
    config.module.rules[1].use[0].options.baseConfig.extends = [
      path.resolve('.eslintrc.js'),
    ];

    const webAliases = {
      'react-native': path.resolve('web/aliases/react-native'),
    };
    Object.assign(config.resolve.alias, webAliases);

    config.plugins.push(
      new webpack.DefinePlugin({
        __DEV__: process.env.NODE_ENV !== 'production',
      }),
    );

    return config;
  },
  paths: function (paths, env) {
    paths.appIndexJs = path.resolve('index.web.js');
    paths.appSrc = path.resolve('.');
    paths.moduleFileExtensions.push('ios.js');
    return paths;
  },
};

Also create a web/aliases/react-native/index.js

// ref to https://levelup.gitconnected.com/react-native-typescript-and-react-native-web-an-arduous-but-rewarding-journey-8f46090ca56b

import {Text as RNText, Image as RNImage} from 'react-native-web';
// Let's export everything from react-native-web
export * from 'react-native-web';

// And let's stub out everything that's missing!
export const ViewPropTypes = {
  style: () => {},
};
RNText.propTypes = {
  style: () => {},
};
RNImage.propTypes = {
  style: () => {},
  source: () => {},
};

export const Text = RNText;
export const Image = RNImage;
// export const ToolbarAndroid = {};
export const requireNativeComponent = () => {};

Now you can just run react-app-rewired start instead of react-scripts start

@danzeeeman
Copy link

This is still a problem

@danzeeeman
Copy link

what is the solution? why did something get deprecated when it is still being used in many many packages and examples?

@frknltrk
Copy link

change all ViewPropTypes.style to PropTypes.style in the source code
don't forget to import PropTypes from "prop-types";
which requires npm install prop-types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants