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

doesn't work with yarn pnp and esm-only modules with import condition #221

Open
danieltroger opened this issue Jan 16, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@danieltroger
Copy link

danieltroger commented Jan 16, 2024

Environment

Node 21.5.0, yarn 4.0.2, macOS 14.2.1 (23C71)

Reproduction

  1. git clone git@github.com:danieltroger/vinxi-repro.git
  2. cd vinxi-repro
  3. yarn
  4. yarn build

Describe the bug

Using yarn pnp (please see https://yarnpkg.com/features/pnp) modules have to be resolved very differently, since node_modules is a concept of the past there - instead, we have de-duplicated, compressed .zip files containing our dependencies.

It seems like mlly is a re-implementation of node-js' module resolution algorithm that has never heard about yarn berry. And because yarn berry doesn't patch mlly, it just explodes when being ran with yarn berry.

Additional context

I really need yarn berrys workspace, package deduplication, patching and linking features and I updated a project to the new solid-start to which mlly is a peerDependency. I'd suggest you to just re-export the working import.meta.resolve when detecting yarn berry since this project seems redundant to me today.

Logs

[vinxi 4:15:41 PM]  ERROR  Error: Error: Cannot find module vinxi/lib/invariant imported from file:///private/tmp/2/vinxi-repro/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules, file:///private/tmp/2/vinxi-repro/, file:///private/tmp/2/vinxi-repro/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules


undefined


[4:15:41 PM]  ERROR  Error: Cannot find module vinxi/lib/invariant imported from file:///private/tmp/2/vinxi-repro/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules, file:///private/tmp/2/vinxi-repro/, file:///private/tmp/2/vinxi-repro/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules

  at resolvePath (.yarn/cache/mlly-npm-1.4.2-75e10242a0-905e3a704c.zip/node_modules/mlly/dist/index.mjs:2074:10)
  at _resolve (.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/dist/shared/nitro.4ea992bc.mjs:534:22)
  at Object.resolveId (.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/dist/shared/nitro.4ea992bc.mjs:580:34)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async PluginDriver.hookFirstAndGetPlugin (.yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:18542:28)
  at async resolveId (.yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:17211:26)
  at async ModuleLoader.resolveId (.yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:17625:15)
  at async Object.resolveId (.yarn/__virtual__/@rollup-plugin-commonjs-virtual-0deef3e5eb/0/cache/@rollup-plugin-commonjs-npm-25.0.7-f5b19139ea-d096af5aed.zip/node_modules/@rollup/plugin-commonjs/dist/es/index.js:588:10)
  at async PluginDriver.hookFirstAndGetPlugin (.yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:18542:28)
  at async resolveId (.yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:17211:26)
  at async ModuleLoader.resolveId (.yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:17625:15)
  at async .yarn/cache/rollup-npm-4.9.2-c65ac1d4a3-c9cd2bd09c.zip/node_modules/rollup/dist/es/shared/node-entry.js:17932:50 



[4:15:41 PM]  ERROR  Error: Cannot find module vinxi/lib/invariant imported from file:///private/tmp/2/vinxi-repro/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules, file:///private/tmp/2/vinxi-repro/, file:///private/tmp/2/vinxi-repro/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/nitropack/node_modules, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules/_index.js, file:///private/tmp/2/vinxi-repro/.yarn/__virtual__/nitropack-virtual-847b2d16a3/0/cache/nitropack-npm-2.8.1-662ce278d2-61738b56fd.zip/node_modules
@pi0
Copy link
Member

pi0 commented Jan 16, 2024

Investigating such issues with higher-order metaframeworks is time-consuming. I appreciate it if you could make a minimal reproduction (with mlly utils only). closing in the meantime.

@pi0 pi0 closed this as completed Jan 16, 2024
@danieltroger
Copy link
Author

Minimal reproduction:

  1. unzip mlly.zip
  2. yarn
  3. yarn start

Output should look like this:

Native resolution works: file:///Users/daniel/.yarn/berry/cache/vinxi-npm-0.1.4-662cb08e69-10c0.zip/node_modules/vinxi/lib/invariant.js
Observe mlly crash below



file:///Users/daniel/.yarn/berry/cache/mlly-npm-1.5.0-dc7923db5f-10c0.zip/node_modules/mlly/dist/index.mjs:2121
  return pcall(resolvePathSync, id, options);
         ^

Error: Error: Cannot find module vinxi/lib/invariant imported from file:///private/tmp/vinxi-repro/node_modules, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules/nitropack/node_modules, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules, file:///private/tmp/vinxi-repro/, file:///private/tmp/vinxi-repro/node_modules/_index.js, file:///private/tmp/vinxi-repro/node_modules, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules/nitropack/, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules/nitropack/node_modules/_index.js, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules/nitropack/node_modules, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules/_index.js, file:///private/tmp/vinxi-repro/.yarn/unplugged/nitropack-virtual-847b2d16a3/node_modules
    at resolvePath (file:///Users/daniel/.yarn/berry/cache/mlly-npm-1.5.0-dc7923db5f-10c0.zip/node_modules/mlly/dist/index.mjs:2121:10)
    at file:///private/tmp/mlly/index.js:10:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v21.5.0

@danieltroger
Copy link
Author

Sorry I included some paths from where I reproduced the issue as part of solid-start in above, but the same error can be observed without them with just

resolvePath("vinxi/lib/invariant", {
  conditions: ["production", "node", "import", "default"]
});

@pi0 pi0 reopened this Jan 16, 2024
@pi0 pi0 changed the title mlly doesn't work with yarn berry (pnp) doesn't work with yarn pnp and esm-only modules with import condition Jan 16, 2024
@pi0
Copy link
Member

pi0 commented Jan 16, 2024

Thanks for the reproduction.

I think same as unjs/jiti#204 (comment) for jiti, for mlly we can leverage import.meta.resolve (that yarn pnp provides) if available but only have to make sure result is not promise (older implementations do this) and if is promise, discard it for sync methods.

Faster solution for module authors is using type: "module" + "default" condition.

@pi0 pi0 added the bug Something isn't working label Jan 16, 2024
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