Description
Bug Report
🔎 Search Terms
yarn, yarn berry, pnp, interface, dependency hoisting, module resolve
and... yarnpkg/berry#5287
🕗 Version & Regression Information
System:
OS: macOS 13.2.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 16.18.0 - /private/var/folders/ld/_l4gwlwn2j1fxtlp_mpc5xr00000gn/T/xfs-e9ba9998/node
Yarn: 3.2.3 - /private/var/folders/ld/_l4gwlwn2j1fxtlp_mpc5xr00000gn/T/xfs-e9ba9998/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v16.18.0/bin/npm
and typescript 5.0.0
I've been experiencing a compatibility issue between the output method of TypeScript's .dts files and yarn's strict dependency resolution approach, which has led to dependency problems in my project.
I would like to provide more details about this issue:
I'm in the following situation: I have 3 packages, A, B, and C, with dependencies in the order of A -> B -> C.
Package A exports the following code (this is part of the actual code):
export interface ThemedStyled<Theme, ...> {...};
export const createThemedStyled<Theme>(theme: Theme): ThemedStyled<Theme, ...>;
Package B uses createThemedStyled from package A:
import { createThemedStyled } from 'A';
export const { styled } = createThemedStyled(myTheme);
Finally, package C uses styled from package B:
export const Button = styled(`...style code`);
After building each package and generating their dts, the output for package C's dts looks like this:
export declare const Button: import('A').ThemedStyled<Theme, ...>;
However, it seems that in pnp, if package C doesn't explicitly have package A as a dependency, A cannot be resolved. This works correctly with nodeLinker: node-modules.
And I don't think this issue is tied to a specific library or the TypeScript compiler.
This issue seems to occur only in the dts, and adding package A to the devDependencies of the problematic package C resolves the issue.
The log is part of result of tsc --traceResolution
about C package.
======== Resolving module '@stitches/react/types/styled-component' from '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/components/input/styled.d.ts'. ========
Explicitly specified module resolution kind: 'NodeNext'.
Resolving in CJS mode with conditions 'node', 'require', 'types'.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/components/input/package.json' does not exist according to earlier cached lookups.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/components/package.json' does not exist according to earlier cached lookups.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/package.json' does not exist according to earlier cached lookups.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/package.json' exists according to earlier cached lookups.
Loading module '@stitches/react/types/styled-component' from 'node_modules' folder, target file type 'TypeScript'.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/components/input/package.json' does not exist according to earlier cached lookups.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/components/package.json' does not exist according to earlier cached lookups.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/dist/package.json' does not exist according to earlier cached lookups.
File '/Users/grapgrap/workspace/flex-frontend/.yarn/__virtual__/@flexteam-linear-virtual-f4877fba30/1/packages/linear/package.json' exists according to earlier cached lookups.
Loading module '@stitches/react/types/styled-component' from 'node_modules' folder, target file type 'JavaScript'.
======== Module name '@stitches/react/types/styled-component' was not resolved. ========
⏯ Playground Link
💻 Code
reproducing repo: https://github.com/flex-jonghyen/pnp-reproduce
🙁 Actual behavior
The problem is importing dependencies of dependencies in .dts files that are unknown to the consumer.
🙂 Expected behavior
The problem does not occur.