0

当我修补这样的依赖项时:

package.json

  "dependencies": 
    "react-native-webview": "patch:react-native-webview@11.0.3#scripts/patches/react-native-webview+11.0.3.patch",
    ...

patches/react-native-webview+11.0.3.patch

diff --git a/apple/RNCWebView.m b/apple/RNCWebView.m
index ff9ff9e0..dfea91a8 100644
--- a/apple/RNCWebView.m
+++ b/apple/RNCWebView.m
@@ -194,12 +194,18 @@ - (void)dealloc
...

yarn当我使用或在本地安装东西时一切正常yarn install。补丁被应用,并且没有错误。

但是,当事情进入 CI 时,我收到如下错误:

**ERROR** Failed to apply patch for package react-native-webview at path
  
    node_modules/react-native-webview

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

    patches/react-native-webview+11.0.3.patch

  Try removing node_modules and trying again. If that doesn't work, maybe there was
  an accidental change made to the patch file? Try recreating it by manually
  editing the appropriate files and running:
  
    patch-package react-native-webview
  
  If that doesn't work, then it's a bug in patch-package, so please submit a bug
  report. Thanks!

    https://github.com/ds300/patch-package/issues

如果我将补丁更改为使用a/node_modules/react-native-webview/apple/RNCWebView.m. 然后我得到一个错误

➤ YN0001: │ Error: react-native-webview@patch:react-native-webview@npm%3A11.0.3#../../scripts/patches/react-native-webview+11.0.3.patch::version=11.0.3&hash=d13297&locator=proj-core%40workspace%3Alib%2Fproj-core: ENOENT: no such file or directory, lstat '/node_modules/react-native-webview/node_modules/react-native-webview/apple/RNCWebView.m'
    at rn (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:172:9625)
    at kn (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:172:9889)
    at Qr.resolveFilename (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:177:21594)
    at Qr.resolveFilename (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:177:21498)
    at Qr.resolveFilename (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:177:21498)
    at Qr.lstatSync (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:177:18712)
    at Qr.lstatPromise (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:177:18671)
    at yt.lstatPromise (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:177:34701)
    at Zu (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:578:7908)
    at YB (/home/user/dev/proj-client/.yarn/releases/yarn-3.0.0.cjs:580:184)
4

2 回答 2

2

这里的问题是您使用两种不同的工具来修补 npm 包,并且在本地使用与 CI 中不同的工具:

  • patch-package作为安装后脚本(如果您检查 package.json 中的“postinstall”条目,您会看到类似的内容patch-package --patch-dir ./scripts/patches
  • yarn 的内置包补丁,patch:在 package.json 中使用。

但是,它们的工作方式不同:

补丁包 纱线的patch:
从项目根目录应用补丁,因此您需要包含node_modules/package-name在差异中。 从包安装目录应用补丁,所以你不需要这样做
需要命名补丁package-name+version.patch 不需要任何特定的命名

这里的解决方案是选择一个,然后更改补丁以与该系统一起使用。因此,例如,如果您重命名文件以删除+version,您将能够仅使用 yarn 的patch:.

于 2021-10-13T20:58:55.663 回答
0

不知道还有没有人关注这个问题。

我的问题yarn.lock.

在我的情况下,我有一个不同的package.json版本,我复制了代码,但它没有工作,因为 yarn.lock 已经生成。我刚刚复制了旧的纱线文件,它工作得很好。

例如,我的 yarn.lock 看起来像这样 在此处输入图像描述

我更改了它以匹配正确的版本 在此处输入图像描述

于 2022-02-17T06:09:31.917 回答