berry: [Bug] Cannot install typescript 4.3.2 with yarn 2 / node_modules linker

  • I’d be willing to implement a fix

Describe the bug

While installing TS 4.3.2 with the node_modules linker yarn 2.4.1 fails with:

➤ YN0013: │ typescript@npm:4.3.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ typescript@patch:typescript@npm%3A4.3.2#builtin<compat/typescript>::version=4.3.2&hash=a45b0e can't be found in the cache and 
➤ YN0013: │ typescript@npm:4.3.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0066: │ typescript@patch:typescript@npm%3A4.3.2#builtin<compat/typescript>::version=4.3.2&hash=a45b0e: Cannot apply hunk #2 (set enableInlineHunks for details)

To Reproduce

{
  "version": "0.59.0",
  "devDependencies": {
    "typescript": "^4.3.0"
  }
}

Environment if relevant (please complete the following information):

  • OS: Windows 10
  • Node version 16.2.0
  • Yarn version 2.4.1

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 34
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

The patch has been released in 2.4.2

Will the fix be backported to yarn 2?

@qrilka You need to be on v2 to use a specific version

yarn set version berry && yarn set version 2.4.2

Fixed in https://github.com/yarnpkg/berry/pull/2543

yarn set version 3.0.0-rc.2

Same issue with @LouisSung. It shows ‘Completed’ but there are error “Cannot apply hunk”. I tried to run my project and the typescript not work.

Will this happen for future TS minor releases?

Most likely if we look at the pattern https://github.com/yarnpkg/berry/blob/464618c2f7baba46a79d66849c1eda00cad1132e/packages/plugin-compat/extra/typescript/gen-typescript-patch.js#L18-L80

In Yarn 3 when the patch doesn’t apply correctly it will just ignore it so node_modules users shouldn’t have any issues

It’s not that it’s “still happening” nor a “regression”, TypeScript released a new version so we need to update the PnP patch. The patch was updated in https://github.com/yarnpkg/berry/pull/3297 which was released in 3.1.0-rc.2 and we haven’t done a full release / backport yet, until we do that the fix is to run the following commands or lock typescript to ~4.3

yarn set version berry && yarn set version canary && yarn

I have the same error within this package.json and yarn 2.4.2. Is this a regression?

{
  "version": "0.59.0",
  "devDependencies": {
    "typescript": "^4.4.2"
  },
  "packageManager": "yarn@2.4.2"
}
➤ YN0000: ┌ Fetch step
➤ YN0013: │ typescript@npm:4.4.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ typescript@patch:typescript@npm%3A4.4.2#builtin<compat/typescript>::version=4.4.2&hash=ddfc1b can't be foun
➤ YN0013: │ typescript@npm:4.4.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0066: │ typescript@patch:typescript@npm%3A4.4.2#builtin<compat/typescript>::version=4.4.2&hash=ddfc1b: Cannot apply hunk #14 (set enableInlineHunks for details)

To reproduce:

code package.json
yarn --version
yarn set version berry && yarn set version 2.4.2
echo "nodeLinker: node-modules" >> .yarnrc.yml
yarn install

@merceyz Is there any plan on the date to release the patch? Seems impact a lot? (at least #2935, #2938, #2944, and #2952)

I can confirm it has been fixed with yarn set version from sources though, thank you for the quick fix : )


[UPDATE1] It’s weird that still failed when installing in Dockerfile… still checking) I got Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation) when doing RUN yarn set version from sources, whereas docker run -it node:12.22.1-buster-slim sh with manually typing in the command works…

[UPDATE2] The set version error is led by #2955 after some cross testing