[Bug] allow node_modules to be a symbolic link
See original GitHub issue- I’d be willing to implement a fix
Describe the bug
For every other directory that yarn wants to write, a symbolic link to a location with write access if sufficient, except for node_modules. Please allow node_modules to be a symbolic link and only check write permissions of its target.
$ yarnpkg add pretty-ms
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 0s 601ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ parse-ms@npm:2.1.0 can't be found in the cache and will be fetched from
➤ YN0013: │ pretty-ms@npm:7.0.1 can't be found in the cache and will be fetched fro
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0001: │ Error: EACCES: permission denied, unlink '/tmp/project1/node_modules'
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 901ms
To Reproduce
The minimal information needed to reproduce your issue (ideally a package.json with a single dep). Note that bugs without minimal reproductions will be closed as non-actionable.
Create project directories as root user and give ownership of files for which yarn needs write access to a normal user (gitlab in this example),
cd /tmp
mkdir projects
cd projects
mkdir .yarn .node_modules
chown gitlab: .yarn .node_modules .
mkdir project1
cd project1
ln -s ../.yarn .
ln -s ../.node_modules node_modules
ln -s ../.yarnrc.yml .yarnrc.yml
ln -s ../package.json package.json
ln -s ../README.md README.md
ln -s ../yarn.lock yarn.lock
ln -s ../.gitattributes .gitattributes
ln -s ../.gitignore .gitignore
ln -s ../.editorconfig .editorconfig
Now switch to gitlab user and create a project, (note: due to a conflict, yarn command is yarnpkg in debian)
su -s /bin/bash - gitlab
cd /tmp/projects/project1/
yarnpkg init -y
touch .yarnrc.yml
if ! grep nodeLinker .yarnrc.yml >/dev/null; then echo "nodeLinker: \"node-modules\"" >>.yarnrc.yml; fi
cat .yarnrc.yml
# prints: nodeLinker: "node-modules"
yarnpkg add pretty-ms
Now it fails trying to remove node_modules. When node-modules is chosen as nodeLinker, it should not try to remove the directory, the user has the required permissions inside the directory pointed by the symbolic link.
This setup is required to follow File System Hierarchy Standard (FHS) in debian, where we want to separate directories where programs are allowed to write and prohibited to write.
So the application files are installed in /usr/share/gitlab and any files or directories that gitlab needs write access is provided as symbolic links to /var/lib/gitlab.
This setup was working well with yarn 1.x, the permission issue started after trying to switch to yarn 2 with node-modules plugin.
IMPORTANT: We strongly prefer reproductions that use Sherlock. Please check our documentation for more information: https://yarnpkg.com/advanced/sherlock
Reproduction
// Sherlock reproduction. For instance:
await packageJsonAndInstall({
dependencies: {
[`packageName`]: `x.y.z`,
},
});
Screenshots
If applicable, add screenshots to help explain your problem.
Environment if relevant (please complete the following information):
- OS: [e.g. OSX, Linux, Windows, …] Debian GNU/Linux unstable/sid
- Node version [e.g. 8.15.0, 10.15.1, …] v12.19.0
- Yarn version [e.g. 2.4.0, …] 2.4.0
Additional context
I’m maintaining gitlab package in debian and I have to use yarn to install node modules not yet packaged in debian. Due to FHS, I cannot provide direct write access to node_modules directory and only a symbolic link with write access at the target location can be provided.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
@joker-777 @merceyz This issue was initially in
nm
linker and was fixed by #2487, but at the time of release of3.2.0
thepnpm
linker cleanup code introduced another issue that affected this use case, which in turn was fixed in: #4206 and merged intomaster
, it is not released yet at the moment. To use Yarn from sources frommaster
one can useyarn set version from sources
yarnpkg set version berry
in postinstall script to update yarn to version 2. See https://salsa.debian.org/ruby-team/gitlab/-/blob/master/debian/rake-tasks.sh#L39 I hope you will reconsider not providing native packages for yarn so that it makes it easy for us to ship yarn directly in main. This installation in postinstall script is only allowed for packages in contrib section and not main. Since we don’t have all node modules packaged gitlab is currently in contrib, but eventually we want to move it back to main after packaging all node modules. If you stick to the current method of only shipping yarn 2 via yarn 1, I request you to at least update the dependencies/build dependencies so we can maintain yarn 1 in main better. We can send pull requests if you are open to merging our patches in yarn 1 branch.