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

Yarn PnP + ESM directory import - Error: Qualified path resolution failed #439

Open
4 of 6 tasks
KcZer0 opened this issue Dec 14, 2023 · 4 comments
Open
4 of 6 tasks
Labels
bug Something isn't working pending triage pr welcome

Comments

@KcZer0
Copy link

KcZer0 commented Dec 14, 2023

Acknowledgements

  • I searched existing issues before opening this one to avoid duplicates
  • I understand this is not a place for seek help, but to report a bug
  • I understand that the bug must be proven first with a minimal reproduction
  • I will be polite, respectful, and considerate of people's time and effort

Minimal reproduction URL

https://codesandbox.io/p/devbox/yarn-tsx-62dstm

Version

v4.9.3 (issue opened: v4.6.2)

Node.js version

v20.10.0

Package manager

yarn v4.2.2

Operating system

Windows

Problem & Expected behavior

What Happened:

When using Yarn PnP and ESM, directory import without explicit /index[.ts] results in error:

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
Error: Qualified path resolution failed: we looked for the following paths, but none could be accessed.

Source path: <project path>/src
Not found: <project path>/src

Reproducible as in the codesandbox


Expected behaviour:

Should run without explicit /index[.ts] in import path


Tried solution:

I fixed this by adding / suffix the import path so it runs loaders.ts#L143. But I don't like the extra /.

So I cloned and linked tsx locally, and found that the error.code in loaders.ts#L202 is ERR_MODULE_NOT_FOUND in Yarn, so it doesn't run the tryDirectory.

Changing tryExtensions to tryDirectory here fixes this problem.
tryDirectory will also fallback to the tryExtensions` in Line 122, so it shouldn't break anything else?

I'm not sure to open PR because it might cause slight slow down due to the multiple tries in tryDirectory, or this could be just a Yarn issue.

Notes:

  • No error for Yarn PnP with commonjs
  • No error for ESM without PnP (nodeLinker: node-modules)

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@KcZer0 KcZer0 added bug Something isn't working pending triage labels Dec 14, 2023
@privatenumber
Copy link
Owner

privatenumber commented Dec 14, 2023

I don't use PnP, but I'd be happy to review a PR with tests if you open one.

shigma added a commit to cordiverse/cordis that referenced this issue Feb 3, 2024
@shigma
Copy link

shigma commented Feb 3, 2024

Changing tryExtensions to tryDirectory here fixes this problem.

@KcZer0 I tried your fix (applying patch to tsx), but my script exited without any output.

nodeLinker: node-modules (link):

image

nodeLinker: pnp without patch (link):

image

nodeLinker: pnp with patch (link):

image

@mrginglymus
Copy link

mrginglymus commented May 8, 2024

This seems to have been fixed in 4.9.0 (or thereabouts - I went from 4.8.2 and 4.9.2 and no longer neede the patch).

My apologies; the problematic dependency was updated to use nodenext resolution.

@KcZer0
Copy link
Author

KcZer0 commented May 9, 2024

No, It's still not fixed in v4.9.3, updated the codesandbox repro.

I was planning to make a pull request to check if yarn is used.
But I think it makes more sense for yarn to add the ERR_UNSUPPORTED_DIR_IMPORT instead.

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

No branches or pull requests

4 participants