Skip to content

fix: crashes when yarn 2 and above is used with the --ignore-engines flag#608

Open
foxnewsnetwork wants to merge 1 commit intods300:masterfrom
foxnewsnetwork:use-package-manager-to-allow-yarn-install
Open

fix: crashes when yarn 2 and above is used with the --ignore-engines flag#608
foxnewsnetwork wants to merge 1 commit intods300:masterfrom
foxnewsnetwork:use-package-manager-to-allow-yarn-install

Conversation

@foxnewsnetwork
Copy link
Copy Markdown

@foxnewsnetwork foxnewsnetwork commented Apr 29, 2026

Background

If you've ever run

yarn run patch-package my-just-patched-in-package

sometimes you'll notice you get these errors

/home/defaultuser/workspace/workspaces/xxx/node_modules/patch-package/dist/makePatch.js:224
        throw e;
        ^
{
  status: 1,
  signal: null,
  output: [
    null,
    Buffer(192) [Uint8Array] [
       27,  91,  51,  49, 109,  27,  91,  49, 109,  85, 110, 107,
      110, 111, 119, 110,  32,  83, 121, 110, 116,  97, 120,  32,
       69, 114, 114, 111, 114,  27,  91,  50,  50, 109,  27,  91,
       51,  57, 109,  58,  32,  85, 110, 115, 117, 112, 112, 111,
      114, 116, 101, 100,  32, 111, 112, 116, 105, 111, 110,  32,
      110,  97, 109, 101,  32,  40,  34,  45,  45, 105, 103, 110,
      111, 114, 101,  45, 115,  99, 114, 105, 112, 116, 115,  34,
       41,  46,  10,  10,  36,  32, 121,  97, 114, 110,  32, 105,
      110, 115, 116,  97,
      ... 92 more items
    ],
    Buffer(0) [Uint8Array] []
  ],
  pid: 103915,
  stdout: Buffer(192) [Uint8Array] [
     27,  91,  51,  49, 109,  27,  91,  49, 109,  85, 110, 107,
    110, 111, 119, 110,  32,  83, 121, 110, 116,  97, 120,  32,
     69, 114, 114, 111, 114,  27,  91,  50,  50, 109,  27,  91,
     51,  57, 109,  58,  32,  85, 110, 115, 117, 112, 112, 111,
    114, 116, 101, 100,  32, 111, 112, 116, 105, 111, 110,  32,
    110,  97, 109, 101,  32,  40,  34,  45,  45, 105, 103, 110,
    111, 114, 101,  45, 115,  99, 114, 105, 112, 116, 115,  34,
     41,  46,  10,  10,  36,  32, 121,  97, 114, 110,  32, 105,
    110, 115, 116,  97,
    ... 92 more items
  ],
  stderr: Buffer(0) [Uint8Array] [],
  error: null
}

by adding a utf-8 encoding command at

spawnSafeSync(`yarn`, ["install", "--ignore-engines"], {
cwd: tmpRepoNpmRoot,
logStdErrOnError: false,
})

        spawnSafeSync(`yarn`, ["install", "--ignore-engines"], {
          cwd: tmpRepoNpmRoot,
          logStdErrOnError: false,
          encoding: 'utf-8'
        })

and logging out the results, we see that the error is actually

====== why is yarn failling? {
  status: 1,
  signal: null,
  output: [
    null,
    "➤ YN0050: The --ignore-engines option is deprecated; engine checking isn't a core feature anymore\n",
    "! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing yarn@3.5.0+sha512.2dc70be5fce9f66756d25b00a888f3ca66f86b502b76750e72ba54cec89da767b938c54124595e26f868825688e0fe3552c26c76a330673343057acadd5cfcf2.\n" +
      '! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager\n' +
      '\n'
  ],
  pid: 104391,
  stdout: "➤ YN0050: The --ignore-engines option is deprecated; engine checking isn't a core feature anymore\n",
  stderr: "! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing yarn@3.5.0+sha512.2dc70be5fce9f66756d25b00a888f3ca66f86b502b76750e72ba54cec89da767b938c54124595e26f868825688e0fe3552c26c76a330673343057acadd5cfcf2.\n" +
    '! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager\n' +
    '\n',
  error: null
}

Root Cause

It seems this happens because --ignore-engines is killed, but sometimes projects use yarn v2 and above (always a mistake, but it can't be helped) and so yarn just crashes (thanks Yehuda)

What can we do about it

In an independent effort in #506 , there is effort (dated to 2023 though) to get yarn v2 and above working (that is, so that we can drop the --ignore-engines )

However, because yarn v2 and above already supports their own variant of patching via yarn patch, it seems unlikely there will much demand to actually drive #506 through to completion

Anyway, in the meantime, the easiest thing to do is just to force yarn to be on v1

Code Changes

  • force yarn to be on v1 with a packageManager directive
  • switch over to using encoding: 'utf-8' in some spawn commands (to generate more helpful errors)

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

Successfully merging this pull request may close these issues.

1 participant