【问题标题】:process.nextTick is not a function (React native, ddp, meteor)process.nextTick 不是函数(React native、ddp、meteor)
【发布时间】:2016-04-23 02:16:24
【问题描述】:

在 react native 时,我正在尝试使用“ddp-client”节点库连接到流星服务器。连接成功后,我在客户端收到以下错误:

2016-01-17 16:14:15.992 [trace][tid:com.facebook.React.JavaScript] ddp message: {"msg":"connected","session":"PGLBqgvoeuXgBtke2"}
2016-01-17 16:14:16.007 [warn][tid:com.facebook.React.JavaScript] process.nextTick is not a function. (In 'process.nextTick(function(_this){
return function(){
return _this._flush();};}(

this))', 'process.nextTick' is undefined)
2016-01-17 16:14:16.008 [error][tid:com.facebook.React.RCTExceptionsManagerQueue] Unhandled JS Exception: process.nextTick is not a function. (In 'process.nextTick(function(_this){
return function(){
return _this._flush();};}(

this))', 'process.nextTick' is undefined)

【问题讨论】:

    标签: meteor react-native ddp


    【解决方案1】:

    process.nextTick 在 React Native 上不存在,所以我们必须对其进行 polyfill。就像process.nextTick = setImmediate 一样简单。

    示例:https://github.com/spencercarli/meteor-todos-react-native/blob/master/ReactNativeTodos/app/config/db/lib/process.polyfill.js

    您需要确保在根组件文件(例如 index.ios.js)中执行此操作

    希望对您有所帮助!

    【讨论】:

    • 在 MDN 上查找 setImmediate此功能是非标准的,不在标准轨道上。不要在面向 Web 的生产站点上使用它
    【解决方案2】:

    我也遇到过同样的问题,但是@Spencer Carli 的回答并不完美,在调试模式下,shiming nextTick 不仅没必要(调试时js运行在v8中),还会让你的应用无法连接开发服务器(我不知道为什么,但确实如此)。所以比较合适的答案是:

    if (!__DEV__) {
      global.process.nextTick = setImmediate
    }
    

    【讨论】:

      【解决方案3】:

      您还可以使用 react-native-meteor 包进行 React Native Meteor 集成。 https://www.npmjs.com/package/react-native-meteor查看此链接以获取文档。

      【讨论】:

        猜你喜欢
        • 2017-04-13
        • 1970-01-01
        • 1970-01-01
        • 2018-01-10
        • 2020-06-27
        • 2015-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多