alt icon indicating copy to clipboard operation
alt copied to clipboard

React-Native support?

Open aksonov opened this issue 9 years ago • 18 comments

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)

aksonov avatar Jun 12 '15 10:06 aksonov

That error looks unrelated to alt

goatslacker avatar Jun 12 '15 17:06 goatslacker

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?

0x80 avatar Jul 09 '15 14:07 0x80

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

froatsnook avatar Jul 09 '15 15:07 froatsnook

@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! :/

0x80 avatar Jul 09 '15 16:07 0x80

From my package.json:

    "alt": "^0.16.10"
    "react-native": "^0.6.0"

froatsnook avatar Jul 09 '15 17:07 froatsnook

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

goatslacker avatar Jul 09 '15 19:07 goatslacker

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

0x80 avatar Jul 09 '15 19:07 0x80

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?

goatslacker avatar Jul 09 '15 20:07 goatslacker

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

froatsnook avatar Jul 09 '15 21:07 froatsnook

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

goatslacker avatar Jul 10 '15 00:07 goatslacker

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

0x80 avatar Jul 10 '15 10:07 0x80

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

Emibob avatar Aug 05 '15 21:08 Emibob

Yup that works well.

goatslacker avatar Aug 05 '15 22:08 goatslacker

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

peterpme avatar Sep 11 '15 18:09 peterpme

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

BerndWessels avatar Sep 23 '15 02:09 BerndWessels

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.

kingdango avatar Dec 13 '15 19:12 kingdango

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

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

goatslacker avatar Dec 13 '15 19:12 goatslacker

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.

jnelken avatar Aug 15 '16 18:08 jnelken