necolas / react-native-web

Cross-platform React UI packages
https://necolas.github.io/react-native-web
MIT License
21.66k stars 1.79k forks source link

react native codepush using Alert #1366

Closed joan-saum closed 5 years ago

joan-saum commented 5 years ago

The problem Hello! I'm trying to be able to have my mobile app accessible through the web thanks to this repo. I'm able to build the app, but when I launch the index.html created, i got some JS errors.

After inspection, I think I found the problem but I don't know how to solve it: I'm using the react-native-codepush repo, and this use the Alert module from React like this:

import React, { Platform } from "react-native"; let { Alert } = React;

When trying to access to the Alert module, in the bundle.js, it try to do this : React.default.Alert but React.default is undefined.

I tried to reimplement the Alert, i created an alias react-native-alert.js with the code from this reimplementing of Alert: https://github.com/Wildtyto/Alert7.js/blob/master/alert7.js

Then i created the alias react-native-web.js to include the Alert :

const ReactNative = require('react-native-web'); const Alert = require('./react-native-alert');

export default { ...ReactNative, Alert };

and in my webpack.config.js, I put the alias of react-native-web like :

resolve { alias: { 'react-native$': path.resolve(__dirname, './aliases/react-native-web'), } }

But still not working.. Did someone try to do something like this?

vladp commented 5 years ago

As a test, did you try to use any other React-native library in your project, (for example react-native-vector-icons), or something else where the author 'officially' supports React-native only ?

If you try those libraries, and you are getting a similar error -- then it means something is wrong your bundler config, and not react-native-web.

It is not clear, but it seems that you are not even using CRA (Create React App), so you will have to search for boiler plate examples that go that route. For example of similar types of issues, see https://github.com/necolas/react-native-web/issues/1354

joan-saum commented 5 years ago

I fix my problem by adding a default export in react-native-web. (copy and paste the change on this PR: https://github.com/necolas/react-native-web/pull/1277)

Not sure why the default export has been removed ?

necolas commented 5 years ago

react-native-codepush doesn't support the web as a platform