berry icon indicating copy to clipboard operation
berry copied to clipboard

[Bug] running `patch-commit` for a package that has a builtin patch fails

Open merceyz opened this issue 3 years ago • 7 comments

Running patch-commit for a package that has a builtin patch now fails with

Internal Error: Assertion failed: Expected the resolution to have been registered
    at PatchCommitCommand.execute (/berry/packages/plugin-patch/sources/commands/patchCommit.ts:82:15)  
    at PatchCommitCommand.validateAndExecute (/berry/.yarn/__virtual__/clipanion-virtual-6f45223597/0/cache/clipanion-npm-3.2.0-rc.4-8470d16306-c9d8ba9e16.zip/node_modules/clipanion/lib/advanced/Command.js:67:26)
    at Cli.run (/berry/.yarn/__virtual__/clipanion-virtual-6f45223597/0/cache/clipanion-npm-3.2.0-rc.4-8470d16306-c9d8ba9e16.zip/node_modules/clipanion/lib/advanced/Cli.js:149:24)
    at Cli.runExit (/berry/.yarn/__virtual__/clipanion-virtual-6f45223597/0/cache/clipanion-npm-3.2.0-rc.4-8470d16306-c9d8ba9e16.zip/node_modules/clipanion/lib/advanced/Cli.js:158:28)
    at exec (/berry/packages/yarnpkg-cli/sources/main.ts:148:7)
    at run (/berry/packages/yarnpkg-cli/sources/main.ts:48:7)

Originally posted by @merceyz in https://github.com/yarnpkg/berry/issues/4218#issuecomment-1072905294

merceyz avatar May 06 '22 22:05 merceyz

I can confirm this for typescript 4.8.4.

yarn 3.2.3 with nodeLinker: node-modules

oxc avatar Oct 13 '22 21:10 oxc

I can confirm this for TypeScript 4.9.3 on Yarn 3.3.0 with nodeLinker: node-modules.

I tried both yarn patch typescript@npm:4.9.3 and yarn patch "typescript@patch:typescript@npm%3A4.9.3#~builtin<compat/typescript>::version=4.9.3&hash=d73830". Neither would successfully commit.

Deco avatar Dec 04 '22 08:12 Deco

Any fix to this? I was able to limp the patch command home (I think) by supplying the resolution stanza myself:

  "resolutions": {
    "[email protected]": "patch:[email protected]#.yarn/patches/typescript-npm-5.0.4-122f6a883a.patch"
  },

but nothing happens when I yarn install, because I think either the builtin-compat one is not being patched or it won't do multiple patches or something. I tried applying my patch to the patched zip, but I don't know how to calculate the checksup to cheat it home. I think that I can't use ts from a git repo because I'll need the yarn patches applied

Any advice on how to arm-twist yarn into applying these changes welcome.

mrflip avatar May 10 '23 18:05 mrflip

More headbanging found a workaround.

  1. expand the base package zip -- in this case .yarn/cache/typescript-npm-5.0.4-122f6a883a-82b94da3f4.zip -- and unzipped it to a directory (paths looked like node_modules/typescript/<stuff>)
  2. visit the node_modules/typescript directory (the one with a package.json) and run touch ./yarn.lock
  3. run yarn pack --out ../../../path/to/desired/location/of/package/typescript-munged.tar.gz
  4. back in your project root, run yarn add typescript@file:./...relative path.../typescript-munged.tar.gz
  5. you will see yarn take your munged version of the package and apply its own magic patches.

This seems to have done the trick.

mrflip avatar May 10 '23 18:05 mrflip

This will happen all the time when there's an entry for the package in resolutions itself - seems some bugs in that.

Downchuck avatar Mar 31 '25 04:03 Downchuck

Also happens when you already have a custom patch for a package and try to add an additional patch via yarn patch --update dom-to-image and yarn patch-commit -s /tmp/xfs-9bd1beff/user.

blutorange avatar Jul 14 '25 09:07 blutorange

any resolution to this problem?

rpk-red avatar Aug 07 '25 19:08 rpk-red