React-native-code-push: Installation failure at react-native link react-native-code-push

Created on 18 Aug 2016  路  7Comments  路  Source: microsoft/react-native-code-push

Hey guys,

Trying to implement code push with an existing react native app. We're using react-native-cli: 0.2.0 and react-native: 0.30.0-rc.0.
During installation npm install --save react-native-code-push@latest
I got an UNMET PEER DEPENDENCY [email protected]

I tried to run react-native link react-native-code-push after that, which crashed (probably due to the error above). full crash log below.

Is this error related to the react-native version I'm on? Any ideas how to resolve? From the getting started guide I see that RN 0.30 is supported.

/Users/shahram/iago/pierogi/node_modules/react-native-code-push/scripts/postlink/ios/postlink.js:26
var oldJsCodeLocationAssignmentStatement = appDelegateContents.match(/(jsCodeLocation = .*)\n/)[1];
                                                                                               ^

TypeError: Cannot read property '1' of null
    at Object.<anonymous> (/Users/shahram/iago/pierogi/node_modules/react-native-code-push/scripts/postlink/ios/postlink.js:26:96)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/shahram/iago/pierogi/node_modules/react-native-code-push/scripts/postlink/run.js:1:63)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
/Users/shahram/iago/pierogi/node_modules/react-native/local-cli/rnpm/core/src/makeCommand.js:21
        throw new Error(`Error occured during executing "${ command }" command`);
        ^

Error: Error occured during executing "node node_modules/react-native-code-push/scripts/postlink/run" command
    at ChildProcess.prelink (/Users/shahram/iago/pierogi/node_modules/react-native/local-cli/rnpm/core/src/makeCommand.js:21:15)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:827:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

All 7 comments

Could you show us your AppDelegate.m file? The automatic patch assumes that you have a jsCodeLocation = xxxx line in that file and attempts to automatically patch that for you. If it still doesn't work, you could simply manually patch it instead following our manual iOS Configuration steps.

Sure, we do have a jsCodeLocation line there. If it helps, we made two modifications to the stock AppDelegate.m file, - added the facebooksdk, added crashlytics integration which overrides the rn logging facility.

AppDelegate.m

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>

#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"

//START Crashlytics stuff
#import <Fabric/Fabric.h>
#import <Crashlytics/Crashlytics.h>

#import <asl.h>
#import "RCTLog.h"
//END Crashlytics stuff

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  //START Fabric Crashlytics stuff
  [Fabric with:@[[Crashlytics class]]];
  RCTSetLogThreshold(RCTLogLevelInfo);
  RCTSetLogFunction(CrashlyticsReactLogFunction);
  //END Fabric Crashlytics stuff

  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"TravelIago"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                openURL:url
                                                      sourceApplication:sourceApplication
                                                             annotation:annotation
                  ];
  // Add any custom logic here.
  return handled;
}

RCTLogFunction CrashlyticsReactLogFunction = ^(
                                               RCTLogLevel level,
                                               __unused RCTLogSource source,
                                               NSString *fileName,
                                               NSNumber *lineNumber,
                                               NSString *message
                                               )
{
  NSString *log = RCTFormatLog([NSDate date], level, fileName, lineNumber, message);

#ifdef DEBUG
  fprintf(stderr, "%s\n", log.UTF8String);
  fflush(stderr);
#else
  CLS_LOG(@"REACT LOG: %s", log.UTF8String);
#endif

  int aslLevel;
  switch(level) {
    case RCTLogLevelTrace:
      aslLevel = ASL_LEVEL_DEBUG;
      break;
    case RCTLogLevelInfo:
      aslLevel = ASL_LEVEL_NOTICE;
      break;
    case RCTLogLevelWarning:
      aslLevel = ASL_LEVEL_WARNING;
      break;
    case RCTLogLevelError:
      aslLevel = ASL_LEVEL_ERR;
      break;
    case RCTLogLevelFatal:
      aslLevel = ASL_LEVEL_CRIT;
      break;
  }
  asl_log(NULL, NULL, aslLevel, "%s", message.UTF8String);


};
@end

Do you happen to have more than one AppDelegate.m file in your project? I suspect this glob search is not yielding the right file.

var ignoreNodeModules = { ignore: "node_modules/**" };
var appDelegatePath = glob.sync("**/AppDelegate.m", ignoreNodeModules)[0];

@geof90 you were right! I did a console.log right after the glob search and found that it was picking up an AppDelegate.m file from sample projects that come packaged with the Facebook SDK. Probably something to watch out for.

To fix it - I just hardcoded the value like so in postlink.js:
var appDelegatePath = "ios/TravelIago/AppDelegate.m"

Instead of doing a glob search, how about just getting the app name from package.json and appending to a string? i.e. "ios/$appname/AppDelegate.m"

@traveliago Thanks for diagnosing this! I think really old versions of React Native used to not nest the iOS files under an "ios" directory, so it could be just "Travellago/AppDelegate.m". Maybe handling these two cases is good enough.. I'll think about this more and send out a fix..

We have the same issue. Thanks for diagnosing this!

EDIT: Submitted a PR based on previous suggestion re using package.json name, but included a fallback on old behavior in case the name does not yield any results. This will retain backwards compatibility with older versions of RN.

Had the same issue. Just added the "Frameworks" folder to the glob's ignore
var ignoreNodeModulesAndPods = { ignore: ["node_modules/**", "ios/Pods/**", "ios/Frameworks/**"] };

Then used it in the actual glob, like:
var appDelegatePaths = glob.sync("**/AppDelegate.+(mm|m)", ignoreNodeModulesAndPods);

Then ran react-native link react-native-code-push and it worked

Was this page helpful?
0 / 5 - 0 ratings

Related issues

diegocouto picture diegocouto  路  4Comments

kevando picture kevando  路  4Comments

Fuhrmann picture Fuhrmann  路  3Comments

ninjz picture ninjz  路  4Comments

DeDuckProject picture DeDuckProject  路  3Comments