yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.37k stars 1.1k forks source link

[Bug?]: Error code for dir import in PnP-ESM #6284

Open KcZer0 opened 4 months ago

KcZer0 commented 4 months ago

Self-service

Describe the bug

Error code when importing directory in Node.js is ERR_UNSUPPORTED_DIR_IMPORT. But in Yarn PnP+ESM it's ERR_MODULE_NOT_FOUND.

This is causing import error for custom loader as in https://github.com/privatenumber/tsx/issues/439

To reproduce

package.json

{
  "type": "module"
}

dir/index.js

export {};

index.js

try {
  const a = await import('./dir');
  console.log(a);
} catch ({ code }) {
  console.log(code); 
  // node: `ERR_UNSUPPORTED_DIR_IMPORT`
  // yarn-pnp-esm: `ERR_MODULE_NOT_FOUND`
}

Environment

System:
  OS: Windows 11 10.0.22631
  CPU: (16) x64 AMD Ryzen 7 6800H with Radeon Graphics         
Binaries:
  Node: 20.11.0 - D:\Temp\AppData\xfs-e4b9d728\node.CMD
  Yarn: 4.2.2 - D:\Temp\AppData\xfs-e4b9d728\yarn.CMD
  npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD

Additional context

No response