yarnpkg / berry

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

[Bug?]: Error: Assertion failed: Writing attempt prevented to xxx which is outside project root: #5297

Open pilaoda opened 1 year ago

pilaoda commented 1 year ago

Self-service

Describe the bug

proj2 link monorepo proj1, then show this error

D:\ts_projects\mine\yarn-bug1\proj2>yarn
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0001: │ Error: Assertion failed: Writing attempt prevented to /D:/ts_projects/mine/yarn-bug1/proj1/packages/lib-b/node_modules/lib-a which is outside project root: /D:/ts_projects/mine/yarn-bug1/proj2
    at mk (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:665:1798)
    at N1e (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:665:2369)
    at Fwt (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:665:8264)
    at lj.finalizeInstall (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:650:26291)
    at async St.linkEverything (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:204:14880)
    at async C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:207:4183
    at async Ct.startSectionPromise (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:170:2973)
    at async St.install (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:207:3989)
    at async C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:439:12527
    at async Function.start (C:\Users\wgx\AppData\Local\node\corepack\yarn\4.0.0-rc.39\yarn.js:170:2068)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 70ms

Expect to get more detailed information about how to fix it. After debugging with berry source code, I guess it may relevant to the mismatch version of fs-extra and lack of lib-a dependency in proj2.

To reproduce

https://github.com/pilaoda/yarn-bug1

Environment

4.0.0-rc.39

Additional context

No response

larixer commented 1 year ago

How do you propose this project should work with node_modules install scheme? I don't see any way. So I'd say it is not a bug, but rather a fundamental limitation of the node_modules scheme.

pilaoda commented 1 year ago

I know it should't work in my case, but it will be helpful if the yarn cli tell me what I done wrong, like showing message about missing dependency or version mismatch. I can never know how to fix the "Error: Assertion failed: Writing attempt prevented" message, until I debug deep in the yarn source code.

larixer commented 1 year ago

I agree, more helpful error message will be appropriate, however it is very difficult to implement the explanation logic for all the cases.

pilaoda commented 1 year ago

I understand. Thanks for all your hard work. I notice that there is an NM_DEBUG_LEVEL env variable help me find out problem, may be we can write doc about it or try to suggest user set this variable when this assertion failed happen.

larixer commented 1 year ago

@pilaoda Yes, we can definitely make this error message more helpful and providing more hints to the user. NM_DEBUG_LEVEL is not part of the public user interface, it's rather more internal troubleshooting tool.

quantizor commented 3 months ago

Check the version of the package between repos, if the linked repo has a higher version that is what caused this issue in my experience

Nantris commented 1 week ago

Check the version of the package between repos, if the linked repo has a higher version that is what caused this issue in my experience

It seems for me that just including anything in dependencies that you also try to link will ALWAYS fail with this error.

What are we supposed to do about this? There seems to be no way forward.

Nantris commented 1 week ago

Hopefully a solution: nmHoistingLimits: workspaces in .yarnrc.yml

I find the lack of guidance for users upgrading from Yarn 1 to be a major pain. It's like if you're not ready to do things the Yarn 2+ way, you're on your own.

Edit: Nope. Just s*** out of luck I guess.

Nantris commented 1 week ago

Why is there no way to limit hoisting to the monorepo? This makes using yarn link impossible because it always complains with this error due to trying to hoist past the monorepo's boundaries... There's no middleground between workspaces and none?