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

Module resolution: Module resolved to indirect dependency rather than direct local one when versions are the same #60556

Open
grigasp opened this issue Nov 22, 2024 · 0 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@grigasp
Copy link

grigasp commented Nov 22, 2024

πŸ”Ž Search Terms

"local module resolution", "module resolution same version"

πŸ•— Version & Regression Information

  • Noticed in 5.6.3, also reproduced with next, 4.6, 4.8, 5.0.
  • I reviewed the FAQ for entries including "resol".

⏯ Playground Link

https://github.com/grigasp/ts-deps-issue

πŸ’» Code

Package [email protected] is released with the following:

export type A1 = number;

Locally we have this package at the same version, but with an additional type:

export type A1 = number;
export type A2 = string;

Locally we also have a package b, that has a dependency on a released version of [email protected] and exports the following type:

import { A1 } from "a";
export type B = A1;

Finally, locally we also have a package c, that has dependencies on local workspace versions of packages b and a and imports types from them both:

// Switching order of these import fixes the build
import { B } from "b";
import { A2 } from "a";

const b: B = 1;
const a2: A2 = "a2";

πŸ™ Actual behavior

When building package c, the build fails with error:

> [email protected] build
> tsc

src/index.ts:3:10 - error TS2305: Module '"a"' has no exported member 'A2'.

3 import { A2 } from "a";

πŸ™‚ Expected behavior

When building package c, TypeScript resolves package a to our local version which does have the A2 type, and the build succeeds.

Additional information about the issue

I tried running tsc -traceResolution for package c and it seems that both - released package and the local one - are assigned the same Package ID:

...
======== Resolving module 'a' from 'E:/temp/ts-deps-issue/packages/c/src/index.ts'. ========
...
======== Module name 'a' was successfully resolved to 'E:/temp/ts-deps-issue/packages/a/lib/index.d.ts' with Package ID 'a/lib/[email protected]'. ========

======== Resolving module 'a' from 'E:/temp/ts-deps-issue/packages/b/lib/index.d.ts'. ========
...
======== Module name 'a' was successfully resolved to 'E:/temp/ts-deps-issue/node_modules/.pnpm/a@file+packages+a+a-1.0.0.tgz/node_modules/a/lib/index.d.ts' with Package ID 'a/lib/[email protected]'. ========
...

I suppose that could cause a cache collision or something like that.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 28, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.8.0 milestone Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants