Similar to: Beanstalk: Node.js deployment - node-gyp fails due to permission denied
My project already has a .npmrc
file with contents unsafe-perm=true
and I haven't had any issues with deployments and the node app running. All of a sudden today I deployed a new git commit and the node app won't start.
When I cd
to /var/app/current
and try to start the app using my standard npm start
command, I get:
Error: /var/app/current/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: cannot open shared object file: Permission denied
Checking the folder permissions I get:
[ec2-user@ip-xxx-xx-x-xxx current]$ ls -la node_modules/
total 144
drwxr-xr-x 619 webapp webapp 20480 Oct 10 14:20 .
drwxr-xr-x 11 webapp webapp 4096 Oct 10 14:20 ..
drwxr-xr-x 2 webapp webapp 4096 Oct 10 14:19 .bin
drwxr-xr-x 6 webapp webapp 91 Oct 10 14:19 @babel
// etc
When I change the folder permissions to belong to ec2-user
by running the following:
sudo chown -R $USER /var/app/current/node_modules
then when I run npm start
the app starts.
When I do a new eb deploy my-environment
then everything defaults back to a broken state because (as I understand it) /var/app/current
is symlinked to the new deploy.
Is anyone else suddenly facing this issue, or does anyone have any pointers?
NPM version:
$ npm -v
> 6.14.13
Node version:
$ node -v
> v14.17.3