Skip to content

[Bug?]: PnP can not resolve module on dts #5287

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

Closed
1 task
flex-jonghyen opened this issue Feb 21, 2023 · 7 comments
Closed
1 task

[Bug?]: PnP can not resolve module on dts #5287

flex-jonghyen opened this issue Feb 21, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@flex-jonghyen
Copy link

flex-jonghyen commented Feb 21, 2023

Self-service

  • I'd be willing to implement a fix

Describe the bug

Updated: 23.03.29

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. ========

To reproduce

https://github.com/flex-jonghyen/pnp-reproduce

Environment

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

Additional context

No response

@flex-jonghyen flex-jonghyen added the bug Something isn't working label Feb 21, 2023
@flex-jonghyen
Copy link
Author

flex-jonghyen commented Feb 21, 2023

@flex-jonghyen flex-jonghyen changed the title [Bug?]: dts can not resolve dependency of dependency. [Bug?]: dts can not resolve dependency of dependency with pnp Feb 22, 2023
@flex-jonghyen flex-jonghyen changed the title [Bug?]: dts can not resolve dependency of dependency with pnp [Bug?]: PnP can not resolve module on dts Mar 2, 2023
@flex-jonghyen
Copy link
Author

I add another case on reproduce repository

@flex-jonghyen
Copy link
Author

flex-jonghyen commented Mar 8, 2023

@arcanis I have been waiting for a response for two weeks, but I have not heard anything. If you could please let me know of any entry that could help solve this issue, I would be happy to investigate it. I will await your response.

@SoYoung210
Copy link

SoYoung210 commented Mar 29, 2023

@arcanis I have the same issue. Can i get a response on this issue? 🙏

@flex-jonghyen
Copy link
Author

I updated the issue with more details.

@merceyz
Copy link
Member

merceyz commented Mar 29, 2023

This looks like a bug in TypeScript, It's emitting imports for dependencies that aren't declared.

It works with node-modules

That reproduction also shows the same issue, the reason it works is because of hoisting.
https://yarnpkg.com/advanced/rulebook/#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies

if package C doesn't explicitly have package A as a dependency, A cannot be resolved

This is the expected behaviour, if a dependency isn't declared PnP wont let you access it.

@flex-jonghyen
Copy link
Author

Finally! Thank you for your answer. I understand that you're saying the output method of TypeScript's  .dts  files does not fit well with yarn's strict dependency resolve approach. I will look into finding a solution in TypeScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants