Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Cannot install typescript 4.3.2 with yarn 2 / node_modules linker #2935

Closed
1 task
xaviergonz opened this issue May 26, 2021 · 18 comments
Closed
1 task
Labels
bug Something isn't working

Comments

@xaviergonz
Copy link

  • 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
@xaviergonz xaviergonz added the bug Something isn't working label May 26, 2021
@merceyz
Copy link
Member

merceyz commented May 26, 2021

Fixed in #2543

yarn set version 3.0.0-rc.2

@merceyz merceyz closed this as completed May 26, 2021
@xaviergonz
Copy link
Author

Will the fix be backported to yarn 2?

@LouisSung
Copy link

LouisSung commented May 27, 2021

Hi @merceyz ,
I tried the yarn@3.0.0-rc.2 but still met the problem QQ

$ yarn set version berry
Resolving berry to a url...
Downloading https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js...
Saving it into /app/.yarn/releases/yarn-berry.cjs...
Updating /app/.yarnrc.yml...
Done!

$ yarn set version 3.0.0-rc.2
➤ YN0000: Downloading https://github.com/yarnpkg/berry/raw/%40yarnpkg/cli/3.0.0-rc.2/packages/yarnpkg-cli/bin/yarn.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-3.0.0-rc.2.cjs
➤ YN0000: Done in 1s 565ms
 YN0066:  typescript@patch:typescript@npm%3A4.3.2#~builtin<compat/typescript>::version=4.3.2&hash=34ad7d: Cannot apply hunk #2
 YN0000:            }
 YN0000:        }YN0000:        ts.getEffectiveTypeRoots = getEffectiveTypeRoots;
 YN0028:  -     function getDefaultTypeRoots(currentDirectory, host) {
 YN0028:  +     function getNodeModulesTypeRoots(currentDirectory, host) {
 YN0000:            if (!host.directoryExists) {
 YN0000:                return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];YN0000:            }YN0028:  -         var typeRoots;YN0028:  +         var typeRoots = [];YN0000:            ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {
 YN0000:                var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);YN0000:                if (host.directoryExists(atTypes)) {
 YN0028:  -                 (typeRoots || (typeRoots = [])).push(atTypes);YN0028:  +                 typeRoots.push(atTypes);YN0000:                }YN0000:                return undefined;YN0000:            });YN0000:            return typeRoots;YN0000:        }YN0000:        var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");
 YN0028:  +     function getPnpTypeRoots(currentDirectory) {
 YN0028:  +         var pnpapi = getPnpApi(currentDirectory);YN0028:  +         if (!pnpapi) {
 YN0028:  +             return [];
 YN0028:  +         }
 YN0028:  +         currentDirectory = ts.sys.resolvePath(currentDirectory);YN0028:  +         var currentPackage = pnpapi.findPackageLocator(currentDirectory + "/");YN0028:  +         if (!currentPackage) {
 YN0028:  +             return [];
 YN0028:  +         }
 YN0028:  +         var packageDependencies = pnpapi.getPackageInformation(currentPackage).packageDependencies;YN0028:  +         var typeRoots = [];YN0028:  +         for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {
 YN0028:  +             var _b = _a[_i], name = _b[0], referencish = _b[1];YN0028:  +             if (name.startsWith(typesPackagePrefix) && referencish !== null) {
 YN0028:  +                 var dependencyLocator = pnpapi.getLocator(name, referencish);YN0028:  +                 var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;YN0028:  +                 typeRoots.push(ts.getDirectoryPath(packageLocation));YN0028:  +             }
 YN0028:  +         }
 YN0028:  +         return typeRoots;YN0028:  +     }
 YN0028:  +     ts.getPnpTypeRoots = getPnpTypeRoots;YN0028:  +     var typesPackagePrefix = "@types/";
 YN0028:  +     function getDefaultTypeRoots(currentDirectory, host) {
 YN0028:  +         var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);YN0028:  +         var pnpTypes = getPnpTypeRoots(currentDirectory);YN0028:  +         if (nmTypes.length > 0 || pnpTypes.length > 0) {
 YN0028:  +             return __spreadArray(__spreadArray([], nmTypes), pnpTypes);
 YN0028:  +         }
 YN0028:  +     }
 YN0000:        function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {
 YN0000:            var traceEnabled = isTraceEnabled(options, host);
 YN0000:            if (redirectedReference) {
 YN0000:  Completed in 36s 384ms

@fyfirman
Copy link

fyfirman commented May 28, 2021

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.

@merceyz
Copy link
Member

merceyz commented May 28, 2021

Will the fix be backported to yarn 2?
@xaviergonz

That specific feature of making them optional probably wont be, no

I tried the yarn@3.0.0-rc.2 but still met the problem QQ
@LouisSung

That's expected, it wont be able to apply the patch but 3.0.0-rc.2 makes it optional which is fine for OP as they're using the node_modules linker

I tried to run my project and the typescript not work.
@fyfirman

The patch was updated in #2889

yarn set version from sources

@LouisSung
Copy link

LouisSung commented May 29, 2021

@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

gluons added a commit to gluons/vue-pack that referenced this issue May 30, 2021
Workaround for Yarn 2 TypeScript problem.
See yarnpkg/berry#2935 and yarnpkg/berry#2938.
@Leksat
Copy link
Contributor

Leksat commented Jun 2, 2021

Why Yarn still tries to patch TypeScript when nodeLinker is set to node-modules? Shouldn't this setting disable PNP completely?

@arcanis
Copy link
Member

arcanis commented Jun 2, 2021

Why Yarn still tries to patch TypeScript when nodeLinker is set to node-modules? Shouldn't this setting disable PNP completely?

No, because it would cause switching between nm and pnp linkers to alter the cached files, which isn't something we want to do (it's a valid use case; some people run nm locally and pnp on their CI).

Is there any plan on the date to release the patch?

It'll be part of 3.0.0-rc.4 which I'm currently working on releasing.

@charles-allen
Copy link

I'm a bit stuck on this -- both solutions hit other issues:

3.0.0-rc.2 => Invalid semver version (no issue?)

Fixed in #2543

yarn set version 3.0.0-rc.2
❯ yarn set version 3.0.0-rc.2         
➤ YN0000: Downloading https://github.com/yarnpkg/berry/raw/%40yarnpkg/cli/3.0.0-rc.2/packages/yarnpkg-cli/bin/yarn.js
➤ YN0001: Error: Invalid semver version

sources => lodash.zip gets confused for a zip archive

The patch was updated in #2889

yarn set version from sources
❯ yarn set version from sources
...
❯ yarn                         
...
➤ YN0001: │ Error: While persisting [...]/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-41fd8dc1af.zip/node_modules/lodash.zip/ -> [...]/node_modules/lodash.zip ENOTDIR: not a directory, scandir '[...]/.yarn/cache/lodash.zip-npm-4.2.0-5299417ec8-41fd8dc1af.zip/node_modules/lodash.zip'

Context:

❯ yarn -v                              
2.4.1
❯ cat .yarnrc.yml
nodeLinker: node-modules # also tried with this commented out

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
    spec: '@yarnpkg/plugin-constraints'
  - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
    spec: '@yarnpkg/plugin-interactive-tools'
  - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
    spec: '@yarnpkg/plugin-typescript'
  - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
    spec: '@yarnpkg/plugin-workspace-tools'

yarnPath: .yarn/releases/yarn-2.4.1.cjs
❯ sw_vers   
ProductName:    macOS
ProductVersion: 11.2.3
BuildVersion:   20D91

@merceyz
Copy link
Member

merceyz commented Jun 3, 2021

The patch has been released in 2.4.2

@charles-allen
Copy link

The patch has been released in 2.4.2

That fixed mine -- successful upgrade to Yarn 2 :)

➤ YN0000: Done with warnings in 1m 44s

milesrichardson added a commit to splitgraph/splitgraph.com that referenced this issue Jul 6, 2021
Core problem is that `yarn berry`, when using `pnp` mode, requires
a patch to `typescript`. But we're using the `node-modules` linker.
Need to upgrade yarn I think

Tracking issues:
    - yarnpkg/berry#2935
    - yarnpkg/berry#2543
    - yarnpkg/berry#2711
milesrichardson added a commit to splitgraph/splitgraph.com that referenced this issue Jul 7, 2021
Core problem is that `yarn berry`, when using `pnp` mode, requires
a patch to `typescript`. But we're using the `node-modules` linker.
Need to upgrade yarn I think

Tracking issues:
    - yarnpkg/berry#2935
    - yarnpkg/berry#2543
    - yarnpkg/berry#2711
@qrilka
Copy link

qrilka commented Jul 15, 2021

The patch has been released in 2.4.2

Is this release even available?
I see

$ yarn set version 2.4.2
Resolving 2.4.2 to a url...
error An unexpected error occurred: "Release not found: 2.4.2".
info If you think this is a bug, please open a bug report with the information provided in "/home/kirill/project-path/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/policies for documentation about this command.

@merceyz
Copy link
Member

merceyz commented Jul 15, 2021

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

yarn set version berry && yarn set version 2.4.2

ali4heydari added a commit to ali4heydari/ali4heydari.github.io that referenced this issue Aug 6, 2021
fix Cannot install typescript 4.3.2 with yarn 2 / node_modules linker
yarnpkg/berry#2935
hoonoh added a commit to hoonoh/aws-spot-price that referenced this issue Aug 31, 2021
roll back to v4.3.5

typescript@patch:typescript@npm%3A4.4.2#builtin<compat/typescript>::version=4.4.2&hash=ddfc1b: Cannot apply hunk #14 (set enableInlineHunks for details)

possibly related: yarnpkg/berry#2935
@Eomm
Copy link

Eomm commented Sep 1, 2021

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

@clemsos
Copy link

clemsos commented Sep 1, 2021

yes this bug still happen with 2.4.2

@merceyz
Copy link
Member

merceyz commented Sep 1, 2021

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 #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

@Eomm
Copy link

Eomm commented Sep 2, 2021

Thanks for the explanation

TypeScript released a new version so we need to update the PnP patch

Will this happen for future TS minor releases?

@merceyz
Copy link
Member

merceyz commented Sep 2, 2021

Will this happen for future TS minor releases?

Most likely if we look at the pattern

{
from: `5d50de3`,
to: `426f5a7`,
onto: `e39bdc3`,
range: `>=3.2 <3.5`,
},
{
from: `5d50de3`,
to: `426f5a7`,
onto: `cf7b2d4`,
range: `>=3.5 <=3.6`,
},
{
from: `5d50de3`,
to: `426f5a7`,
onto: `cda54b8`,
range: `>3.6 <3.7`,
},
{
from: `5d50de3`,
to: `2f85932`,
onto: `e39bdc3`,
range: `>=3.7 <3.9`,
},
{
from: `5d50de3`,
to: `3af06df`,
onto: `551f0dd`,
range: `>=3.9 <4.0`,
},
{
from: `6dbdd2f`,
to: `6dbdd2f`,
onto: `56865f7`,
range: `>=4.0 <4.1`,
},
{
from: `746d79b`,
to: `746d79b`,
onto: `69972a3`,
range: `>=4.1 <4.2`,
},
// https://github.com/merceyz/TypeScript/tree/merceyz/pnp-4.2
{
from: `8e0e8703b9c95013aec7819e4593d099cdf7763a`,
to: `545d5a8c5409dac447a668d4e7d315702fd115d6`,
onto: `bfc55b5762443c37ecdef08a3b5a4e057b4d1e85`,
range: `>=4.2 <4.3`,
},
// https://github.com/merceyz/TypeScript/tree/merceyz/pnp-4.3
{
from: `530aad19e4ac19d35cb6b200168c91ce86cb0050`,
to: `6d7d4d2ce0df8e65a2c86a20c014c053ef530ea3`,
onto: `28e3e6ff2f49f1dbf06d31809ec73dbe42f1aa63`,
range: `>=4.3 <4.4`,
},
// https://github.com/merceyz/TypeScript/tree/merceyz/pnp-4.4
{
from: `793bfe32745bf6797924354b0fd5be62cf01950c`,
to: `88a10595c32309fc26eb4a7f5a858d98e883dae0`,
onto: `a10409ccaa3604790dc45f52ef0402eb49015dcf`,
range: `>=4.4`,
},

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

@yarnpkg yarnpkg locked as resolved and limited conversation to collaborators Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants