Skip to content

7.1: same package is installed twice in two connected project, TS sees only one (get TS2883) #65601

Open

Description

🔎 Search Terms

TS2883, likely not portable, deduplicated package, duplicate package, subpath export, declaration emit

🕗 Version & Regression Information

⏯ Playground Link

https://github.com/elevatebart/repro-with-package-installed-twice

💻 Code

app/node_modules/pkg/     identical copy of pkg@1.0.0
app/src/index.ts          export type { Rules } from "pkg"; export { first } from "../../lib/src/first";
app/tsconfig.json         declaration: true, rootDir: "..", moduleResolution: bundler
lib/node_modules/pkg/     identical copy of pkg@1.0.0
lib/src/first.ts          import type { Rules } from "pkg"; export function first(rules: Rules) { return Object.values(rules)[0]; }

pkg exports "." and "./utils/arrayable"; Rules is Record<string, Arrayable<number>>, with Arrayable from pkg/utils/arrayable.

🙁 Actual behavior

When checking types,

lib/src/first.ts(3,17): error TS2883: The inferred type of 'first' cannot be named without a reference to 'Arrayable' from '../../app/node_modules/pkg/utils/arrayable'. This is likely not portable. A type annotation is necessary.

🙂 Expected behavior

As in 6.0.3 and 7.0.2, first.d.ts declares first(rules: Rules): import("pkg/utils/arrayable").Arrayable<number>. From lib, pkg/utils/arrayable resolves to lib's copy, which is the same package and version as the deduplicated file in app.

Additional information about the issue

Context

I realize this setup with two different projects with two different node_modules folders is unusual.
It's the best way we managed to resolve the Open core (compared to Open Source) paradigm at kestra and it has bitten us before.

I would understand if this was dismissed. I thought it would be useful to know the change of behavior.

More info to solve it

  • With the two copies at different versions, 7.1 emits fine, so it looks tied to the redirect that deduplicates identical packages.
  • Workarounds that avoid it: a paths entry that maps pkg to one copy, installing pkg once (symlinked or in a shared parent folder), or annotating the return type.
  • We hit it in a project that type-checks sources from a sibling checkout, where @popperjs/core (pulled in by element-plus) is installed in both checkouts.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions