yarnpkg / berry

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

[Bug?]: Different node_modules layout on Node.js 23 when `enableTransparentWorkspaces` is `false` #6567

Open JLHwung opened 1 month ago

JLHwung commented 1 month ago

Self-service

Describe the bug

Yarn 4.3.1 generated different nm layout on Node.js 23 when enableTransparentWorkspaces is false. I also tested on Yarn 4.5.1, the nm layout is identical to yarn 4.3.1.

To reproduce

git clone https://github.com/babel/babel && cd babel
nvm use 23 && rm -rf node_modules && yarn install
find ./node_modules -type d -print | sort > nm-23.txt

nvm use 22 && rm -rf node_modules && yarn install
find ./node_modules -type d -print | sort > nm-22.txt

diff nm-22.txt nm-23.txt

Expected: there are no differences between these two file. As there are no differences when running yarn on node.js 22 vs node.js 20.

Actual: Their are differences from @babel/* packages, and it seems that yarn 4 on Node.js 23 are hoisting less packages to the top level than Node.js 22/20.

Environment

System: OS: macOS 14.7 CPU: (10) arm64 Apple M1 Max Binaries: Node: 20.13.1 - /private/var/folders/qq/f33w791j6wgb405mt9lgpw3w0000gn/T/xfs-b5fa2615/node Yarn: 4.5.1 - /private/var/folders/qq/f33w791j6wgb405mt9lgpw3w0000gn/T/xfs-b5fa2615/yarn npm: 10.5.2 - ~/.nvm/versions/node/v20.13.1/bin/npm bun: 0.5.1 - ~/.bun/bin/bun npmPackages: jest: ^30.0.0-alpha.2 => 30.0.0-alpha.2

Additional context

This issue currently blocks https://github.com/babel/babel/pull/16912.

JLHwung commented 1 month ago

It seems that the behaviour on Node.js 23 actually does more good to the Babel repo than the upgrade disruption: We have nailed several unsound imports that won't be revealed unless pnp mode is enabled. At this time this issue no longer blocks Babel's adaption to Node.js 23.

JLHwung commented 1 month ago

I guess this issue might be related to https://github.com/nodejs/node/issues/55410. If yarn used path.resolve internally, then the behaviour change in node 23 might prevent yarn hoisting some packages. Hopefully it will be reverted in the next release.