question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to apply patch with multiple file changes with yarn

See original GitHub issue

With yarn v1.10.1 and postinstall-postinstall

Error Message

v5:

  This error was caused because Git cannot apply the following patch file:
    patches/react-native-firebase+5.0.0.patch

  This is usually caused by inconsistent whitespace in the patch file.

v6:

  This error was caused because patch-package cannot apply the following patch file:
    patches/react-native-firebase+5.0.0.patch

Diff

patch-package
--- a/node_modules/react-native-firebase/dist/index.d.ts
+++ b/node_modules/react-native-firebase/dist/index.d.ts
@@ -1179,6 +1179,8 @@ declare module 'react-native-firebase' {
          */
         getToken(): Promise<string>;

+        getAPNSToken(): Promise<string>;
+
         deleteToken(authorizedEntity?: string, scope?: string): Promise<void>;

         /**
--- a/node_modules/react-native-firebase/dist/modules/messaging/index.js
+++ b/node_modules/react-native-firebase/dist/modules/messaging/index.js
@@ -46,6 +46,10 @@ export default class Messaging extends ModuleBase {
     return getNativeModule(this).getToken();
   }

+  getAPNSToken() {
+    return getNativeModule(this).getAPNSToken();
+  }
+
   deleteToken(authorizedEntity, scope) {
     return this.app.iid().deleteToken(authorizedEntity, scope);
   }
--- a/node_modules/react-native-firebase/ios/RNFirebase/messaging/RNFirebaseMessaging.m
+++ b/node_modules/react-native-firebase/ios/RNFirebase/messaging/RNFirebaseMessaging.m
@@ -126,6 +126,20 @@ RCT_EXPORT_METHOD(getToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseR
     }
 }

+RCT_EXPORT_METHOD(getAPNSToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
+    NSData *apnsToken = [FIRMessaging messaging].APNSToken;
+    if (apnsToken) {
+        const char *data = [apnsToken bytes];
+        NSMutableString *token = [NSMutableString string];
+        for (NSInteger i = 0; i < apnsToken.length; i++) {
+            [token appendFormat:@"%02.2hhX", data[i]];
+        }
+        resolve([token copy]);
+    } else {
+        reject(@"messaging/fcm-token-error", @"Failed to retrieve APNS token.", nil);
+    }
+}
+
 RCT_EXPORT_METHOD(requestPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
     if (RCTRunningInAppExtension()) {
         reject(@"messaging/request-permission-unavailable", @"requestPermission is not supported in App Extensions", nil);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ds300commented, Jan 21, 2019

I’m closing this to tidy up. Have completely refactored the patch application code and tested it in different envs. Seems to work well. If you still have trouble feel free to open another issue.

6.0 will be leaving beta very very shortly!

1reaction
LoicMahieucommented, Nov 28, 2018

My bad, I was running with patch-package@5. I tried with v6 and it works. The initial patch was huge, package’s node_modules was included in the patch. I ended to this:

$ yarn patch-package gatsby --include="^(dist|cache-dir)\/.*" --exclude="\.map$"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting errors when patching a npm package - Stack Overflow
The problem here is that you're using two different tools to patch the npm package, and using a different one locally than in...
Read more >
Patch-package NPM
Specify the name for the directory in which to put the patch files. ... This happens even after failing to apply patches because...
Read more >
Create Patches - GitLab Docs
To apply patch files, store .patch files that contain the changes in a specific ... Use the git diff command to create a...
Read more >
patch(1) - Linux manual page - man7.org
patch - apply a diff file to an original ... If that fails, and the maximum fuzz factor is set to 2 or...
Read more >
patch-package | Fix broken node modules instantly - YouTube
patch -package is a tool that has saved me a couple of times when I found a bug in an npm package and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found