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

SDK 0.6.0 Unusable with React Native Packager #134

Closed
Hybrid-Force opened this issue Aug 26, 2015 · 11 comments
Closed

SDK 0.6.0 Unusable with React Native Packager #134

Hybrid-Force opened this issue Aug 26, 2015 · 11 comments
Assignees

Comments

@Hybrid-Force
Copy link
Contributor

Description

0.6.0版本兼容Browserify,利用package.json的browser配置可以在浏览器和Node环境中能各自加载适用于当前环境的模块。但是,在React Native环境中,JS SDK完全不能用了。

React Native的packager不检查package.json中的browser的配置选项,不能选择性的加载适用的模块。这导致React Native尝试加载错误的xmlhttprequest模块并出错且无法启动应用。

0.6.0版本的这个错误比之前的[AsyncStorage的问题](issue #115)更加严重,AsyncStorage的问题只是导致不能持久话session,而这个问题导致应用无法启动。

Screenshot

image

@leeyeh
Copy link
Contributor

leeyeh commented Aug 27, 2015

React Native的packager不检查package.json中的browser的配置选项

facebook/react-native#10 (comment)
facebook/react-native#2208

FYI.

@Hybrid-Force
Copy link
Contributor Author

哦,好像是react native packager的问题。packager的确检查了package.json的browser配置,但是对于形如"xmlhttprequest": "./lib/browserify-wrapper/xmlhttprequest-browser.js"这样的配置就不能处理了。

@leeyeh
Copy link
Contributor

leeyeh commented Aug 27, 2015

已在 react-native 0.10.0 中确认无法运行。

@leeyeh leeyeh reopened this Aug 27, 2015
@leeyeh leeyeh self-assigned this Aug 27, 2015
@Hybrid-Force
Copy link
Contributor Author

我去开了一个React Native Packager的bug

另外,React Native Packer不能解析path模块。

@leeyeh
Copy link
Contributor

leeyeh commented Aug 27, 2015

👍

@smalllixin
Copy link

@Hybrid-Force 目前有什么work around可以解决这个问题么?

@leeyeh
Copy link
Contributor

leeyeh commented Sep 8, 2015

@smalllixin 这个 issue 里提到的两个问题:

  1. react-native 不完全支持 browser 字段导致 xmlhttprequest 未找到
  2. react-native 不支持 path 模块

暂时的解决方法:

  1. patch react-native with https://github.com/facebook/react-native/pull/2499.patch
  2. 手动改 avoscloud-sdk

@Hybrid-Force
Copy link
Contributor Author

@smalllixin 在react-native merge @leeyeh 同学的PR之前,我有一个临时的branch暂时解决了上述的两个问题以及对 asyc storage的适配。

  1. react-native 的packager不完全支持browser字段,所以不依赖于 browser字段,通过lib/xmlhttpreqeust.js模块来加载浏览器或者node module。
  2. react-native 的packager不包含path模块的支持,因此手动添加path module的依赖。
  3. 顺便加了个'lib/storage.js' 来适配react-native 的 AsyncStorage。增加了一个AV.User.currentAsync API。通过这样的方法来获取当前用户:
AV.User.currentAsync()
    .then(user => console.log(user));

另外, @leeyeh 同学发现react-native对WebSocket的支持也有点问题,估计JS IM SDK的使用会有影响。

@h3l
Copy link

h3l commented Oct 22, 2015

qq20151023-0 2x
@Hybrid-Force 你好,我这边使用了你的临时branch后报了上图的错误,麻烦问下如何解决

@leeyeh
Copy link
Contributor

leeyeh commented Oct 22, 2015

@h3l 请升级到 [email protected] 试试。

@h3l
Copy link

h3l commented Oct 22, 2015

@leeyeh 非常感谢,解决了,没想到npm install avoscloud-sdk —save默认安装的是0.6几版本的

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

4 participants