Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.nextTick is not a function (React native, ddp, meteor)

On react native, I am trying to use 'ddp-client' node library to connect to a meteor server. Just after the connection is successful, I am getting the following ERROR on client side:

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)
like image 870
Magesh khanna Avatar asked Jan 18 '16 01:01

Magesh khanna


2 Answers

process.nextTick doesn't exist on React Native so we've got to polyfill it. That is as simple as process.nextTick = setImmediate.

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

You'll want to make sure you do this in your root component file (eg index.ios.js)

Hope this helps you!

like image 121
Spencer Carli Avatar answered Nov 19 '22 05:11

Spencer Carli


I've come across the same problem, but @Spencer Carli's answer is not perfect, in debugging mode, shimming nextTick is not only unnecessary (js runs in v8 when debugging), it will also make your app failed to connect the development server (I don't know why, but it actually does). So the more suitable answer is:

if (!__DEV__) {
  global.process.nextTick = setImmediate
}
like image 34
xiechao06 Avatar answered Nov 19 '22 06:11

xiechao06