Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to apply patch for package, but versions match #1

Closed
staltz opened this issue May 22, 2017 · 2 comments
Closed

Failed to apply patch for package, but versions match #1

staltz opened this issue May 22, 2017 · 2 comments

Comments

@staltz
Copy link

staltz commented May 22, 2017

patch-package version: v2.0.0

Reproduction:

I don't have a repo to point to, but in my case I'm using [email protected] as installer, I have some transitive dependencies in node_modules, e.g. vfile is in my node_modules but it's not in my package.json. I have a patches/vfile:1.4.0.patch file, and the version installed is also v1.4.0.

Expected: patch-package to patch a package without errors

Actual:

click here
***ERROR***
patch-package requires yarn as a local peer-dependency

Applying patches to node_modules...
[email protected][email protected] ✔

**ERROR** Failed to apply patch for package vfile

  Patch was made for version 1.4.0
  Meanwhile node_modules/vfile is version 1.4.0

  Run:

     patch --forward -p1 -i patches/vfile:1.4.0.patch

  To generate rejection files and see just what the heck happened.

I also got the rejection files, but it doesn't explain anything new:

patching file node_modules/vfile/index.js
patch unexpectedly ends in middle of line
Hunk #1 FAILED at 43.
1 out of 1 hunk FAILED -- saving rejects to file node_modules/vfile/index.js.rej
index.js.rej
***************
*** 43,49 ****
  var SEPARATOR = '/';
  
  try {
-     SEPARATOR = require('pa' + 'th').sep;
  
  
  
--- 43,49 ----
  var SEPARATOR = '/';
  
  try {
+     SEPARATOR = require('path').sep;
  
  
  
index.js.orig
/**
 * @author Titus Wormer
 * @copyright 2015 Titus Wormer
 * @license MIT
 * @module vfile
 * @fileoverview Virtual file format to attach additional
 *   information related to processed input.  Similar to
 *   `wearefractal/vinyl`.  Additionally, `VFile` can be
 *   passed directly to ESLint formatters to visualise
 *   warnings and errors relating to a file.
 * @example
 *   var VFile = require('vfile');
 *
 *   var file = new VFile({
 *     'directory': '~',
 *     'filename': 'example',
 *     'extension': 'txt',
 *     'contents': 'Foo *bar* baz'
 *   });
 *
 *   file.toString(); // 'Foo *bar* baz'
 *   file.filePath(); // '~/example.txt'
 *
 *   file.move({'extension': 'md'});
 *   file.filePath(); // '~/example.md'
 *
 *   file.warn('Something went wrong', {'line': 2, 'column': 3});
 *   // { [~/example.md:2:3: Something went wrong]
 *   //   name: '~/example.md:2:3',
 *   //   file: '~/example.md',
 *   //   reason: 'Something went wrong',
 *   //   line: 2,
 *   //   column: 3,
 *   //   fatal: false }
 */

'use strict';

/* eslint-env commonjs */

var proto;

var SEPARATOR = '/';

try {
    SEPARATOR = require('pa' + 'th').sep;
} catch (e) { /* empty */ }

/**
 * Construct a new file message.
 * ...
 * ...
@ds300
Copy link
Owner

ds300 commented May 22, 2017

Thanks for the detailed report!

Looks like a CRLF/LF issue: https://unix.stackexchange.com/questions/1395/what-does-patch-unexpectedly-ends-in-middle-of-line-mean

Can you post the contents of the patch file and note whether it ends in a linefeed? Also, try adding a linefeed to the end of the file and see if the patch can be applied.

@staltz
Copy link
Author

staltz commented May 22, 2017

Yes, that seemed to be the issue. Thanks!
I forgot to mention I manually edited the patch files because the nested dependency differed in its package.json contents (as usually, the package.json of an installed dependency is kind of... messed up) and I messed up with the linefeed at the end of the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants