-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
Fixed in #2543
|
Will the fix be backported to yarn 2? |
Hi @merceyz , $ 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 |
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. |
That specific feature of making them optional probably wont be, no
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
The patch was updated in #2889
|
@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
|
Workaround for Yarn 2 TypeScript problem. See yarnpkg/berry#2935 and yarnpkg/berry#2938.
Why Yarn still tries to patch TypeScript when |
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).
It'll be part of 3.0.0-rc.4 which I'm currently working on releasing. |
I'm a bit stuck on this -- both solutions hit other issues: 3.0.0-rc.2 => Invalid semver version (no issue?)
❯ 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
❯ 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:
|
The patch has been released in 2.4.2 |
That fixed mine -- successful upgrade to Yarn 2 :) ➤ YN0000: Done with warnings in 1m 44s |
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
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
Is this release even available?
|
@qrilka You need to be on v2 to use a specific version
|
fix Cannot install typescript 4.3.2 with yarn 2 / node_modules linker yarnpkg/berry#2935
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
I have the same error within this
To reproduce:
|
yes this bug still happen with 2.4.2 |
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 yarn set version berry && yarn set version canary && yarn |
Thanks for the explanation
Will this happen for future TS minor releases? |
Most likely if we look at the pattern berry/packages/plugin-compat/extra/typescript/gen-typescript-patch.js Lines 18 to 80 in 464618c
In Yarn 3 when the patch doesn't apply correctly it will just ignore it so |
Describe the bug
While installing TS 4.3.2 with the node_modules linker yarn 2.4.1 fails with:
To Reproduce
Environment if relevant (please complete the following information):
The text was updated successfully, but these errors were encountered: