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

[Bug?]: Package subpath imports don't work with the ESM loader #4846

Closed
1 task
evanw opened this issue Sep 13, 2022 · 1 comment
Closed
1 task

[Bug?]: Package subpath imports don't work with the ESM loader #4846

evanw opened this issue Sep 13, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@evanw
Copy link

evanw commented Sep 13, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

It appears that when PnP is enabled, Yarn's ESM loader doesn't support subpath imports correctly (i.e. imports that start with # in a package with an imports map in its package.json file). It looks like Yarn thinks it's a package instead, which then fails to be imported because it's not listed in that package's dependencies.

To reproduce

$ yarn init -2
$ yarn set version 3.2.3
$ yarn config set pnpEnableEsmLoader true
$ yarn add aws-jwt-verify@3.1.0
$ echo 'import "aws-jwt-verify"' > in.mjs
$ yarn node in.mjs
.pnp.cjs:8466
  return Object.defineProperties(new Error(message), {
                                 ^

Error: aws-jwt-verify tried to access #node-web-compat, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: #node-web-compat (via "#node-web-compat/package.json")
Required by: aws-jwt-verify@npm:3.1.0 (via .yarn/cache/aws-jwt-verify-npm-3.1.0-1694314cd9-b978817018.zip/node_modules/aws-jwt-verify/dist/esm/jwt-rsa.js)

    at makeError (.pnp.cjs:8466:34)
    at resolveToUnqualified (.pnp.cjs:9385:21)
    at Object.resolveToUnqualified (.pnp.cjs:9529:26)
    at resolve$1 (.pnp.loader.mjs:224:31)
    at ESMLoader.resolve (node:internal/modules/esm/loader:530:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:251:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:40)
    at link (node:internal/modules/esm/module_job:78:36)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (2) x64 DO-Regular
  Binaries:
    Node: 16.14.0 - /tmp/xfs-e3802538/node
    Yarn: 3.2.3 - /tmp/xfs-e3802538/yarn
    npm: 8.7.0 - ~/node/bin/npm

Additional context

Someone filed an issue about this package not working with esbuild's implementation of PnP: evanw/esbuild#2545. But Yarn itself doesn't work with this package either. I'm guessing this is a bug with Yarn.

@evanw evanw added the bug Something isn't working label Sep 13, 2022
@merceyz
Copy link
Member

merceyz commented Sep 13, 2022

I'm guessing this is a bug with Yarn.

We haven't implemented it yet, closing as a duplicate of #3843

@merceyz merceyz closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2022
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

2 participants