2
votes

I'm trying to figure out how to get the permissions to work for me with my node_modules directory. Here's the problem...

user1 goes to a folder with a package.json and runs npm install resulting in a node_modules directory with the owner and group user1.

user2 then goes to that folder (it's a shared folder) and tries running something like npm install --save some_dep, but they don't have permissions on this directory so it fails.

Okay, that's fine.. so I chown -R the node_modules to be a shared group which both users are in.

Now user2 can run his command successfully resulting in a folder node_modules/some_dep. But now user1 doesn't have access to this folder.

So I try using a setgid permission on the node_modules directory. Something like chmod -R g+s node_modules. The result is exactly the same as before - when a user runs a NPM command the resulting directory gets the wrong group and permissions.

So I tried using ACLs, but the result is again the same.. the directories resulting from a user running an NPM command will not respect the permissions of the host folder.

Maybe this has something to do with how NPM dependencies are built. Maybe they are built elsewhere and then moved?

Is there any way to set permissions that are effective for that directory and all future subdirectories in such a way that I can make this work?

I could just run everything as root all the time... but this is clearly not ideal.

1

1 Answers

1
votes

This appears to be due to a design flaw in npm. When creating the node_modules folder, npm (for reasons no one can explain) executes chown on the folder explicitly. Rather than relying on the OS to properly set permissions, npm mucks with problems, messes up your permissions, and makes it pretty much impossible to use it in a shared environment without periodic manual runs of chmod/chown.

This is likely the source of the endless trail of permissions-related issues people have trying to use npm.

Developers promise (for the nth time) this problem is fixed in later versions: https://github.com/npm/npm/blob/db9cde008ce855bdac801bb6649cbfb5bb7911ac/changelogs/CHANGELOG-2.md#v2120-2015-06-18