Skip to content

[Bug?]: TypeScript 7 RC fails to install because the legacy TypeScript compat patch targets removed JS compiler files #7191

Closed

Description

@hamidrezahanafi

Self-service

  • I'd be willing to implement a fix

Describe the bug

Summary

Installing [email protected] with Yarn fails because the built-in TypeScript compatibility patch is still applied to TypeScript 7. The patch was designed for the legacy JS compiler package layout and includes hunks for files such as lib/_tsc.js, which no longer exist in the TypeScript 7 native compiler package.
This should be addressed by: microsoft/typescript-go#1966

Fix PR limiting the patch to < 7 : #7190

To reproduce

Reproduction

yarn add [email protected]

### Environment

```shell
System:
    OS: macOS 26.5.1
    CPU: (14) arm64 Apple M4 Pro
  Binaries:
    Node: 24.15.0 - /private/var/folders/c0/g9kchlzs17l77g7jpxkyrrh40000gp/T/xfs-89a14381/node
    Yarn: 4.15.0 - /private/var/folders/c0/g9kchlzs17l77g7jpxkyrrh40000gp/T/xfs-89a14381/yarn
    npm: 11.12.1 - /Users/hamidrezahanafi/.nvm/versions/node/v24.15.0/bin/npm
    bun: 1.3.4 - /Users/hamidrezahanafi/.bun/bin/bun
  npmPackages:
    jest: ^30.3.0 => 30.3.0

Additional context

Actual Behavior

Yarn attempts to apply the legacy TypeScript compat patch:

typescript@patch:typescript@npm%3A7.0.1-rc#optional!builtin<compat/typescript>

and fails with:

ENOENT: no such file or directory, lstat '/node_modules/typescript/lib/_tsc.js'

Expected Behavior

Yarn should not apply the legacy JS TypeScript compat patch to TypeScript 7, since TypeScript 7 uses the new native compiler package layout.

Activity

  1. added
    bug
    on Jun 18, 2026
  2. wojtekmaj commented on Jun 18, 2026

    @wojtekmaj
    Contributor

    Temporary workaround that unblocked us on a nodeLinker: node-modules setup.

    Since we don't use PnP, we don't need the TypeScript compat patch semantically; we only needed to prevent Yarn from rewriting the typescript descriptor to patch:...builtin<compat/typescript>, because the TS 7 RC package no longer has the JS compiler files that the legacy patch expects.

    We added this local plugin:

    // .yarn/plugins/plugin-disable-typescript-compat.cjs
    module.exports = {
      name: "plugin-disable-typescript-compat",
      factory: (require) => {
        const { structUtils } = require("@yarnpkg/core");
    
        return {
          hooks: {
            reduceDependency: async (dependency) => {
              if (structUtils.stringifyIdent(dependency) !== "typescript")
                return dependency;
    
              if (!dependency.range.startsWith("patch:"))
                return dependency;
    
              const source = dependency.range.match(/^patch:([^#]+)/)?.[1];
    
              if (!source)
                return dependency;
    
              return {
                ...dependency,
                range: structUtils.parseDescriptor(decodeURIComponent(source)).range,
              };
            },
          },
        };
      },
    };

    And registered it before other plugins:

    plugins:
      - path: .yarn/plugins/plugin-disable-typescript-compat.cjs
        spec: "plugin-disable-typescript-compat"

    After that, yarn up typescript@rc resolved to plain typescript@npm:7.0.1-rc and installs/checks worked again. This is definitely a workaround rather than a fix, but it may be useful for other node-modules projects that don't rely on Yarn's PnP TypeScript patch.

  3. hamidrezahanafi commented on Jun 18, 2026

    @hamidrezahanafi
    ContributorAuthor

    Thanks @wojtekmaj for the workaround, I think my PR #7190 limiting the patch version should also be safe to land and unblock nodeLinker: node-modules fleet.

  4. wojtekmaj commented on Jun 18, 2026

    @wojtekmaj
    Contributor

    And your solution is undeniably better! Except for one detail: it needs to be released. I'm too eager to try the RC out to wait 😁

  5. maik-bol commented on Jun 18, 2026

    @maik-bol

    Amazing, thanks for this workaround. I'd solved it by patching the compat package to add the missing files as re-export stubs, but disabling the patch via a plugin is much cleaner, so I've switched to it.

    I'll follow this thread until @hamidrezahanafi's PR (#7190) lands, since gating the builtin patch is the cleanest proper fix.

    One caveat though: as written it bounds the patch to TS < 7, which fixes installing [email protected] directly but not the recommended TS6/TS7 side-by-side setup, where typescript is aliased to @typescript/typescript6 (a 6.x shim that is still < 7 and lacks the patched files, so it keeps failing).

    I left a remark on the PR with a repro and two options to cover that case too. @hamidrezahanafi would you be open to extending it?

  6. abhi-airspace-intelligence commented on Jun 19, 2026

    @abhi-airspace-intelligence

    Temporary workaround that unblocked us on a nodeLinker: node-modules setup.

    Since we don't use PnP, we don't need the TypeScript compat patch semantically; we only needed to prevent Yarn from rewriting the typescript descriptor to patch:...builtin<compat/typescript>, because the TS 7 RC package no longer has the JS compiler files that the legacy patch expects.

    We added this local plugin:

    // .yarn/plugins/plugin-disable-typescript-compat.cjs
    module.exports = {
    name: "plugin-disable-typescript-compat",
    factory: (require) => {
    const { structUtils } = require("@yarnpkg/core");

    return {
      hooks: {
        reduceDependency: async (dependency) => {
          if (structUtils.stringifyIdent(dependency) !== "typescript")
            return dependency;
    
          if (!dependency.range.startsWith("patch:"))
            return dependency;
    
          const source = dependency.range.match(/^patch:([^#]+)/)?.[1];
    
          if (!source)
            return dependency;
    
          return {
            ...dependency,
            range: structUtils.parseDescriptor(decodeURIComponent(source)).range,
          };
        },
      },
    };
    

    },
    };
    And registered it before other plugins:

    plugins:

    • path: .yarn/plugins/plugin-disable-typescript-compat.cjs
      spec: "plugin-disable-typescript-compat"
      After that, yarn up typescript@rc resolved to plain typescript@npm:7.0.1-rc and installs/checks worked again. This is definitely a workaround rather than a fix, but it may be useful for other node-modules projects that don't rely on Yarn's PnP TypeScript patch.

    Note this is subtly wrong if you rely on immutable installs in your CI: this is what fixed it for me:

    module.exports = {
      name: 'plugin-disable-typescript-compat',
      factory: require => {
        const { structUtils } = require('@yarnpkg/core');
    
        return {
          hooks: {
            reduceDependency: async dependency => {
              if (structUtils.stringifyIdent(dependency) !== 'typescript') return dependency;
    
              if (!dependency.range.startsWith('patch:')) return dependency;
    
              const source = dependency.range.match(/^patch:([^#]+)/)?.[1];
    
              if (!source) return dependency;
    
              const unpatched = structUtils.parseDescriptor(decodeURIComponent(source));
    
              return structUtils.makeDescriptor(dependency, unpatched.range);
            },
          },
        };
      },
    };
    
  7. maik-bol commented on Jun 19, 2026

    @maik-bol

    We do rely on immutable installs, but everything seemed right, thanks for this but what does it exactly subtly fix?

  8. added a commit that references this issue on Jul 31, 2026
  9. added a commit that references this issue on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions