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.

Inconsistent information provided when patching fails

See original GitHub issue

This issue seems to be similar to #19 so I updated my yarn and node versions. I am on 64-bit Windows 10 with yarn v1.1.0, node 8.6.0 and npm v5.3.0. I can successfully generate a patch file and I have successfully applied the very same file in the past with $yarn prepare. I have noticed that this issue seems to occur when I switch branches in git.

$ yarn prepare
yarn run v1.1.0
$ patch-package
patch-package: Applying patches...

**ERROR** Failed to apply patch for package react-native-deprecated-custom-components

  This error was caused because react-native-deprecated-custom-components has changed since you
  made the patch file for it. This introduced conflicts with your patch,
  just like a merge conflict in Git when separate incompatible changes are
  made to the same piece of code.

  Maybe this means your patch file is no longer necessary, in which case
  hooray! Just delete it!

  Otherwise, you need to manually fix the patch file. Or generate a new one

  To generate a new one, just repeat the steps you made to generate the first
  one, but accounting for the changes in react-native-deprecated-custom-components.

  i.e. make changes, run `patch-package react-native-deprecated-custom-components`, and commit.

  To manually fix a patch file, Run:

     patch -p1 -i patches/react-native-deprecated-custom-components+0.1.1.patch --verbose --dry-run

  To list rejected hunks. A 'hunk' is a section of patch file that describes
  one contiguous area of changes. They are numbered from 1 and begin with lines
  that look like this:

    diff --git a/node_modules/thing/thing.js b/node_modules/thing/thing.json

  Remove the conflicting hunks, then manually edit files in

    node_modules/react-native-deprecated-custom-components

  to reflect the changes that the conflicting hunks were supposed to make.

  Then run `patch-package react-native-deprecated-custom-components`

  Info:
    Patch was made for version 0.1.1
    Meanwhile node_modules/react-native-deprecated-custom-components is version 0.1.1

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Note that the info: section seems to indicate a belief that the version numbers are out of sync but they are actually identical. Better error messages would be helpful for debugging this.

Here is the package.json file from the library I’m trying to patch in my node_modules folder:

{
  "name": "react-native-deprecated-custom-components",
  "version": "0.1.1",
  "description": "Deprecated custom components that originally shipped with React Native",
  "repository": {
    "type": "git",
    "url": "git@github.com:facebookarchive/react-native-custom-components.git"
  },
  "main": "src/CustomComponents.js",
  "dependencies": {
    "fbjs": "~0.8.9",
    "immutable": "~3.7.6",
    "prop-types": "^15.5.10",
    "react-timer-mixin": "^0.13.2",
    "rebound": "^0.0.13"
  },
  "peerDependencies": {
    "react-native": "*"
  }
}

and here is the patch file itself:

diff --git a/node_modules/react-native-deprecated-custom-components/src/NavigatorBreadcrumbNavigationBar.js b/node_modules/react-native-deprecated-custom-components/src/NavigatorBreadcrumbNavigationBar.js
index 704216e..09efbbe 100644
--- a/node_modules/react-native-deprecated-custom-components/src/NavigatorBreadcrumbNavigationBar.js
+++ b/node_modules/react-native-deprecated-custom-components/src/NavigatorBreadcrumbNavigationBar.js
@@ -93,9 +93,9 @@ class NavigatorBreadcrumbNavigationBar extends React.Component {
       titleContentForRoute: PropTypes.func,
       iconForRoute: PropTypes.func,
     }),
-    navState: React.PropTypes.shape({
-      routeStack: React.PropTypes.arrayOf(React.PropTypes.object),
-      presentedIndex: React.PropTypes.number,
+    navState: PropTypes.shape({
+      routeStack: PropTypes.arrayOf(PropTypes.object),
+      presentedIndex: PropTypes.number,
     }),
     style: ViewPropTypes.style,
   };

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
rodnolancommented, Sep 29, 2017

the .gitattributes change fixed the problem! I decided to document the steps that I followed before I even began the experiment so I’m leaving those steps here in case someone can benefit from them.

Here are the steps I’m using to reproduce this.

cd \temp
react-native init patchpackagetest
cd patchpackagetest

yarn add --dev patch-package
react-native run-android

The sample app compiles, installs and runs without error. The next step is to add a dependency that requires a patch.

yarn add react-native-fbsdk@0.6.1
react-native link react-native-fbsdk

I change line 61 of FBSDKPackage.java to this:

// @Override invalid as of React Native 0.47.0 

The app compiles and runs so the next step is to generate the patch.

PS C:\temp\patchpackagetest> yarn patch-package react-native-fbsdk
yarn run v1.1.0
$ "C:\temp\patchpackagetest\node_modules\.bin\patch-package" "react-native-fbsdk"
☑ Creating temporary folder
☑ Building clean node_modules with yarn
☑ Diffing your files with clean files
✔ Created file patches/react-native-fbsdk+0.6.1.patch
Done in 70.35s.
PS C:\temp\patchpackagetest>

The generated patch file is 132,706 lines long… too big for here so I made it available [here] instead (https://raw.githubusercontent.com/rodnolan/patchpackagetest/master/patches/react-native-fbsdk%2B0.6.1.patch).

git init .
git add .
git commit -m "generated patch file"
git remote add origin git@github.com:rodnolan/patchpackagetest.git
git push origin master

Deleted the patch file

del .\patches\react-native-fbsdk+0.6.1.patch

reinstated it

git reset --hard

dumped node_modules

del .\node_modules\*

updated package.json and committed

	"scripts": {
		"start": "node node_modules/react-native/local-cli/cli.js start",
		"test": "jest",
		"prepare": "patch-package"
	},
PS C:\temp\patchpackagetest> git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")
PS C:\temp\patchpackagetest> git add .\package.json
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
PS C:\temp\patchpackagetest> git commit -m 'adding patch-package script'
[master b217047] adding patch-package script
 1 file changed, 2 insertions(+), 1 deletion(-)
PS C:\temp\patchpackagetest> git push origin master
Enter passphrase for key '/c/Users/RodNolan/.ssh/rodnolan_id_rsa':
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 328 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:rodnolan/patchpackagetest.git
   0ff8eaf..b217047  master -> master
PS C:\temp\patchpackagetest>

I tried to re-install dependencies and got this nice new error message:

PS C:\temp\patchpackagetest> yarn install
yarn install v1.1.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.2: The platform "win32" is incompatible with this module.
info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from
stallation.
[3/4] Linking dependencies...
warning "babel-jest@21.2.0" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-alpha || ^7.0.0
eta || ^7.0.0".
[4/4] Building fresh packages...
$ patch-package
patch-package: Applying patches...

**ERROR** Failed to apply patch for package react-native-fbsdk

  This error was caused because Git cannot apply the following patch file:

    patches/react-native-fbsdk+0.6.1.patch

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


  It seems you're running Windows. Make sure you have a .gitattributes file
  in the root of your project with the following line:

    patches/*.patch eof=lf

  Then check out the patch files again to make them work properly

    rm -rf patches
    git checkout HEAD patches

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
PS C:\temp\patchpackagetest>

updated git attributes with the suggested addition, committed that change… (now I understand what you meant by the last comment!)

del .\patches\react-native-fbsdk+0.6.1.patch
git reset --hard
del .\node_modules\*

so I removed the existing patch file again, reapplied the fix, regenerated the patch with

yarn patch-package react-native-fbsdk

and got this:

diff --git a/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java b/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
index af2c3a9..d566538 100644
--- a/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
+++ b/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
@@ -58,7 +58,7 @@ public class FBSDKPackage implements ReactPackage {
         );
     }
 
-    @Override
+    // @Override react native 0.47.0 makes this invalid
     public List<Class<? extends JavaScriptModule>> createJSModules() {
         return Collections.emptyList();
     }

That’s more in line with what I expected so I committed that new file and re-installed by dependencies again

del .\node_modules\*
yarn install

Bingo!

PS C:\temp\patchpackagetest> yarn install
yarn install v1.1.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.2: The platform "win32" is incompatible with this module.
info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from in
stallation.
[3/4] Linking dependencies...
warning "babel-jest@21.2.0" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-alpha || ^7.0.0-b
eta || ^7.0.0".
[4/4] Building fresh packages...
$ patch-package
patch-package: Applying patches...
react-native-fbsdk@0.6.1 ✔
Done in 24.68s.
PS C:\temp\patchpackagetest>

Thanks for this fix!

1reaction
ds300commented, Sep 28, 2017

I’ve figured out what’s causing this issue, and it goes away if I re-write the patch files to get rid of CRLFs before applying them, regardless of whether the source files they’re patching have CRLFs or just LFs. I’ll push a fix out tonight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The risks of failed patch management | TechTarget
Patch management pitfalls include pushing out updates too quickly and devices going offline. But the most significant risk when patch ...
Read more >
Patching OMS With the Plugin Update Patch Fails With Error ...
Patching the 13.4 OMS with the Plugin Update patch fails with the error: WARNING: Could not apply the patch "30971925" because the "oracle....
Read more >
Recommended Practice for Patch Management of Control ...
The patch management of industrial control systems software used in CIKR is inconsistent at best and nonexistent at worst. Patches are important to...
Read more >
How to Give Support Information on False Patch and Other ...
Result Code Result String Description 0x80240002 WU_E_MAX_CAPACITY_REACHED The maximum capacity of the service w... 0x80240003 WU_E_UNKNOWN_ID An ID cannot be found. 0x80240004 WU_E_NOT_INITIALIZED The object could...
Read more >
MDVA-33281 patch: inventory inconsistency issues
For info about other patches available in QPT, refer to the Patches available in QPT in our developer documentation. Was this article helpful?...
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