执行 yarn 时,报错:Failed to apply patch for package laravel-mix. This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed.

1、执行 yarn 时,报错:Failed to apply patch for package laravel-mix.This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed.。如图1

图1

PS E:\wwwroot\object> yarn
yarn install v1.22.15
[1/5] Validating package.json...
[2/5] Resolving packages...
success Already up-to-date.
$ patch-package
patch-package 6.4.7
Applying patches...
concat@1.0.3 ✔
eslint-plugin-jsonc@2.3.0 ✔

**ERROR** Failed to apply patch for package laravel-mix

  This happened because the patch file patches\laravel-mix+6.0.43.patch could not be parsed.

  If you just upgraded patch-package, you can try running:

    cd patches\laravel-mix+6.0.43.patc
    patch -p1 -i h
    npx patch-package laravel-mix
    cd ../..

  Otherwise, try manually creating the patch file again.

  If the problem persists, please submit a bug report:

    https://github.com/ds300/patch-package/issues/new?title=Patch+file+parse+error&body=%3CPlease+attach+the+patch+file+in+question%3E


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

2、查看 Git 日志,patches\laravel-mix+6.0.43.patch 的上一个版本是:patches\laravel-mix+6.0.48.patch。如图2

图2

3、删除掉目录:node_modules 后,再次执行:yarn,仍然报同样的错误。如图3

图3

4、参考提示,执行:npx patch-package laravel-mix。如图4

图4

PS E:\wwwroot\object> npx patch-package laravel-mix
patch-package 6.4.7
• Creating temporary folder
• Installing laravel-mix@6.0.43 with yarn
• Diffing your files with clean files
⁉️  Not creating patch file for package 'laravel-mix'
⁉️  There don't appear to be any changes.
npm notice
npm notice New minor version of npm available! 8.1.2 -> 8.12.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.12.1
npm notice Run npm install -g npm@8.12.1 to update!
npm notice

5、再次执行:yarn,仍然报错。参考:https://github.com/ds300/patch-package/issues/191 。将换行符从 CRLF 替换为 LF。不再报错。如图5

图5

永夜