goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 322 forks source link

React-Native support? #328

Open aksonov opened 9 years ago

aksonov commented 9 years ago

Trying to add stores/actions to my react-native project and got following error:

Error: Cannot find package main file for package: /Users/aksonov/Documents/PZ/React/node_modules/react-native/node_modules/react-tools/src
    at DependecyGraph.resolveDependency (/Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:229:13)
    at /Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:122:22
    at Array.forEach (native)
    at collect (/Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:120:25)
    at /Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:135:9
    at Array.forEach (native)
    at collect (/Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:120:25)
    at /Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:135:9
    at Array.forEach (native)
    at collect (/Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:120:25)
    at /Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:135:9
    at Array.forEach (native)
    at collect (/Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:120:25)
    at DependecyGraph.getOrderedDependencies (/Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/DependencyGraph/index.js:141:3)
    at /Users/aksonov/Documents/PZ/Pods/React/packager/react-packager/src/DependencyResolver/haste/index.js:96:35
    at tryCatcher (/Users/aksonov/Documents/PZ/Pods/React/node_modules/bluebird/js/main/util.js:24:31)
goatslacker commented 9 years ago

That error looks unrelated to alt

0x80 commented 9 years ago

I'm running into the same problem / error and tracked it down to:

const connectToStores = require('alt/utils/connectToStores');

Is there anything required to make Alt work with react-native?

froatsnook commented 9 years ago

I'm running alt with reactive native without any issues! I just npm installed everything.

0x80 commented 9 years ago

@froatsnook What versions are you using?

Really the only thing I have to do to break my app is const connectToStores = require('alt/utils/connectToStores');

I don't get it! :/

froatsnook commented 9 years ago

From my package.json:

    "alt": "^0.16.10"
    "react-native": "^0.6.0"
goatslacker commented 9 years ago

Yes this might be an issue. I'll patch it.

0x80 commented 9 years ago

@goatslacker great to hear that you're on to something! I'm using 0.17.1, so I guess there is a difference there.

goatslacker commented 9 years ago

No difference. It's just that connectToStores uses React when it should be using react-native.

I'm actually not sure how it works for @froatsnook

maybe they've got some aliasing going on in their build system that maps react to react-native?

froatsnook commented 9 years ago

I think it's working for me because I call listen and unlisten manually.

goatslacker commented 9 years ago

Requiring the package alone should probably give you an error, since it requires React to build the connectToStores class...again, idk /shrug.

0x80 commented 9 years ago

For now I managed to get things working by doing a find/replace of "react" with "react-native" in all of the utils files

Emibob commented 9 years ago

Hey @goatslacker I am running into the same issue. Is @0x80 's fix an acceptable solution? Thank you.

goatslacker commented 9 years ago

Yup that works well.

peterpme commented 9 years ago

Hello everyone, future everyone who may have an issue with React Native + Alt (and webpack)

If you're using webpack, you can try to set an alias inside resolve:

  resolve: {
    alias: {
      'react': 'react-native'
    }
  }

https://github.com/mjohnston/react-native-webpack-server/issues/58#issuecomment-139622341

BerndWessels commented 9 years ago

Hello

I tried @0x80 fix, but that didn't help.

I don't know how to do @ppiekarczyk fix in a react-native android application?

I get Uncaught SyntaxError: Unexpected token ILLEGAL in alt\lib\index.js : 1

alt version 0.17.3 react-native version 0.11.0

Please help, thank you Bernd

kingdango commented 8 years ago

I am using OOTB react-native sample app (react-native version 0.16.0) and alt (0.18.1). Alt works fine without alt/utils but when I try to use the 'alt/utils/..." decorators I run into this error:

image

I don't even know what webpack is so I'm not sure where to specify the 'react': 'react-native' alias.

goatslacker commented 8 years ago

I believe its require('alt/utils/lib/connectToStores')

There's this though: https://github.com/altjs/react

jnelken commented 8 years ago

Looking through my web and mobile app alt node_modules, I see that the appropriatealt/utils files exist in ^0.17.0 but not in ^0.18.5 (on my react-native app). Using npm install alt-utils with the path alt-utils/lib/... fixed this for me when importing connectToStores.