I have a Ubuntu Server on DigitalOcean, which hosts some websites. I just built a mean.js stack app on my mac, and I plan to deploy it to production, thus to this existing server.
I followed this link to install node.js and mongodb, etc. Then, rather than cloning the sample app of mean.js, I cloned my own app from the github:
sudo git clone https://github.com/softtimur/myapp.git /opt/myapp
cd /opt/myapp
sudo mkdir public/tmp/
sudo npm install
npm start
Then, in a browser, I entered https://xxx.xx.xx.xx:3000/#/new. On the server side, I got an error:
router.post /mkdir
{ Error: EACCES: permission denied, mkdir 'public/tmp/sAlTI6NDo5NQcO-lAAAA/'
at Error (native)
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: 'public/tmp/sAlTI6NDo5NQcO-lAAAA/' }
This is because in the backend of my app, it tries to create a folder in public/tmp/ by fs.mkdir(...) where fs = require('fs').
So does anyone know to how to give the server this permission?
PS: I also tried to run
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
but it did not help.
The issue is that you created public/tmp/ as root:
sudo mkdir public/tmp/
But you're running the app as $USER, which will most likely not be allowed to write to that directory.
To fix:
sudo chown -R $USER:$GROUP public/tmp/
Related
I've hosted a NodeJS backend on Beanstalk using an EC2 instance. It was and is still working well with old code but now if I want to update the application by deploying new code, it gives me errors as:
> phantomjs-prebuilt#2.1.16 install /tmp/deployment/application/node_modules/phantomjs-prebuilt
> node install.js
Considering PhantomJS found at /usr/local/bin/phantomjs
Found PhantomJS at /usr/local/bin/phantomjs ...verifying
Writing location.js file
Error checking path, continuing Error: EACCES: permission denied, open '/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/location.js'
at Object.openSync (fs.js:462:3)
at Object.writeFileSync (fs.js:1362:35)
at writeLocationFile (/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/util.js:84:6)
at Promise._successFn (/tmp/deployment/application/node_modules/phantomjs-prebuilt/install.js:375:11)
at nextTickCallback (/tmp/deployment/application/node_modules/kew/kew.js:47:28)
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/location.js'
}
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1606204791845/phantomjs-2.1.1-linux-x86_64 -> /tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom
Phantom installation failed [Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1606204791845/phantomjs-2.1.1-linux-x86_64' -> '/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom'] {
errno: -13,
code: 'EACCES',
syscall: 'link',
path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1606204791845/phantomjs-2.1.1-linux-x86_64',
dest: '/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom'
} Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1606204791845/phantomjs-2.1.1-linux-x86_64' -> '/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom'
I've been stuck with this situation for 20 days now, I've tried various solutions from the web but none has worked so far. I don't even know why there's PhantomJS in my code, maybe because of any 3rd party package I've added.
Solutions I've tried:
Tried installing/uninstalling PhantomJS from my project and then uploading it.
Tried installing it on the EC2 Linux machine by taking access through Putty and using commands (support link used - here):
sudo npm install phantomjs -g //Didn't work
sudo npm install phantomjs#2.1.1 -g --unsafe-perm //Didn't work
sudo npm install phantomjs-prebuilt#2.1.16 -g --unsafe-perm
//Installing globally using NPM support docs
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
npm install -g phantomjs
npm install -g phantomjs-prebuilt
NPM_CONFIG_PREFIX=~/.npm-global //also tried this
Tried this solution from official github repo issue #722
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
I've also tried many random solutions but so far nothing has worked. There was no keypair associated with my EC2 instance, so accessing it was a separate mess. Also, Yes, I'm new to backend development.
So, my question is How to fix this PhantomJS issue?
This is a bit old now, hope the OP managed to get it sorted! Since I spent a couple of days trying to fix this myself, thought I'd drop some info in here of the things I did to solve this issue, taken from various sources, for anyone coming along later!
ssh to your eb environment using your AWS identity key (found in your home dir, ~/.ssh) and the dns of the application, the deployed name of the app assigned by AWS, e.g:
ssh -i <key>.pem <app name>-env.<chars>.<region>.elasticbeanstalk.com
Once you're in:
>cd /var/app/current directory.
create empty file
>touch .npmrc
>sudo vi .npmrc
place unsafe-perm=true into it and exit vi (press <esc> and type :wq).
This will allow the gyp process sparked up by npm to actually do something.
>sudo npm install phantomjs-prebuilt
...
>sudo yum install fontconfig
You'll need a way to have all this formalised and reproducible in a build process so you don't need to log in each time there's an update applied!!
Sources:
https://forums.aws.amazon.com/thread.jspa?threadID=290964
error while loading shared libraries: libfontconfig.so.1 on cent os
I am running an Ubuntu EC2 server and followed the tutorial provided by AWS to install nvm and node, but when I try to run npm install, I'm thrown an error:
Error: EACCES: permission denied, access '/var/www/app'
Please try running this command again as root/Administrator.
The standard procedure with an EC2 Ubuntu service appears to only provide a ubuntu user with sudo privileges and no access to root so I tried to run sudo npm install, but I receive sudo: npm: command not found. The reason why I believe this is happening is because nvm is located at /home/ubuntu/.nvm/versions/node/v6.12.3/bin/node, which root might not have access to?
Is it possible to point root to the this directory location for this command or is there a different solution?
You're getting that error because you do not have write permission for your user on that /var/www/app.
You can follow the answer here to give permissions to that folder.
https://askubuntu.com/questions/749697/how-do-i-give-myself-access-to-var-www-to-create-and-edit-files-and-folders-in
You are getting the error about npm not being installed when you use sudo because it is not installed for the admin user. I would avoid installing node and npm through sudo though. Just go with changing the folder permissions.
Whenever I try something with yarn on Ubuntu 16.04 server.
It gives an error.
I am currently using nodejs v8.10.0
yarn install v1.5.1
error An unexpected error occurred: "EACCES: permission denied, scandir '/home/ubuntu/.config/yarn/link'".
info If you think this is a bug, please open a bug report with the information provided in "/home/ubuntu/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Anyone know why this is happening?
It's likely a unix permission related problem. There is a solution posted on the dev's github page. Try to run the following command
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
Reference: EACCES: permission denied .config/configstore/bower-github.json #2262
I had this problem as well, I found on another thread that my config folder was owned by root, which created several permissions issues.. I changed owner to my user and this error went away.
See top answer on this thread
Unable to access 'git/attributes'
I've just run into a strange problem with fs reading a file.
I have node application run from a deployment manager (strongloop strong-pm) as the following user "strong-pm".
No matter what permissions I give to the file I'm trying to open throug the node app, I get
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
worker:1 Error: EACCES, permission denied '/root/my_dir/file.txt'
at Object.fs.openSync (fs.js:432:18)
at Object.fs.readFileSync (fs.js:286:15)
I've tried everything:
sudo chown -R strong-pm:strong-pm /root/my_dir
sudo chmod -R 777 /root/my_dir
sudo chmod 777 /root/my_dir/file.txt
adding the strong-pm to a group
then adding that group to the directory...
Still no luck.. any ideas?
Thanks!
System: Ubuntu 14.04 x64 on DigitalOcean
Rather than trying it inside node, try to switch to that user and read the file:
su strong-pm
cat /root/my_dir/file.txt
If that works, make sure node is running using that user.
Try this:
.{otherPATH}/root/my_dir/file.txt
It seemed like the issue was that the /root directory was protected and so subdirectories were not accessible by node somehow
I've been trying to run an npm install on my package.json file, but I'm having a lot of trouble. It keeps saying "Error: Attempt to unlock XXX, which hasn't been locked" on all my dependences. Here's one of them:
Error: Attempt to unlock tbd#~0.6.4, which hasn't been locked
at unlock (/usr/local/lib/node_modules/npm/lib/cache.js:1304:11)
at cb (/usr/local/lib/node_modules/npm/lib/cache.js:646:5)
at /usr/local/lib/node_modules/npm/lib/cache.js:655:20
at /usr/local/lib/node_modules/npm/lib/cache.js:1290:7
at /usr/local/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
at Object.oncomplete (fs.js:107:15)
If I try to run it as sudo, it seems to get further and start installing some packages, but some new errors popup instead:
> chokidar#0.8.1 postinstall /Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/chokidar
> node setup-deps.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
node.js:811
var cwd = process.cwd();
^
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:811:23)
at startup (node.js:58:13)
at node.js:902:3
npm ERR! error rolling back Error: ENOTEMPTY, rmdir '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q'
npm ERR! error rolling back karma#0.10.9 { [Error: ENOTEMPTY, rmdir '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q']
npm ERR! error rolling back errno: 53,
npm ERR! error rolling back code: 'ENOTEMPTY',
npm ERR! error rolling back path: '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/q' }
npm ERR! Error: ENOENT, chown '/Users/tkirchner/Documents/Projects/mm-datatable/node_modules/karma/node_modules/socket.io/lib/socket.io.js'
I recently updated my node and npm installations. So maybe that has something to do with it. Also, most of my development has been at the office and today I'm working over VPN, so maybe that has something to do with it too.
Any ideas?
As per photusenigma at: https://github.com/npm/npm/issues/4815
Run these commands in a terminal window (note - DON'T replace the $USER part...thats a linux command to get your user!):
sudo chown -R $USER ~/.npm
sudo chown -R $USER /usr/local/lib/node_modules
...and...if you're on a mac (like I am), and still see errors after running these commands, then run this last one and you should be good. (Recommend you try testing before you do this one. I don't like changing the permissions on the ENTIRE /usr/local directory unless it really seems necessary!)
sudo chown -R $USER /usr/local
I worked with a co-worker this afternoon and figured out what the problem was. My ".npm" folder in my home directory was owned by the root user instead of myself. I'm not sure what happened to cause that. Maybe I installed node or npm as the root admin at one point. In any case I just ran sudo chown -R [username] .npm and I was finally able to run npm install commands from my projects again!
In my case the issue was invoking npm with a user that does not have a HOME directory, so for example the following command would fail:
sudo -u someUser npm install
The solution is to provide a HOME directory, where someUser has write access:
sudo -u someUser HOME=/some/directory npm install
Had the same issue and fixed it by changing the persmissions as per the accepted answer:
sudo chown -R $USER ~/.npm
However, the second command should be avoided as it downgrades the permissions of a system resource (sudo chown -R $USER /usr/local/lib/node_modules). Not a good idea.
For the record: "usr" in /usr/local stands for Unix System Resources.
None of this worked for me. I had to run literally as root by doing the following:
sudo su -
sudo npm install forever -g
Then the package installed on Linux Ubuntu 14.04.
The following command should fix permission issues:
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
You can read about another officially recommended solutions here:
https://docs.npmjs.com/getting-started/fixing-npm-permissions
My solution:
sudo chown -R $USER /usr/local/lib/node_modules/NAMEOFMODULE
in my case was :
sudo chown -R $USER /usr/local/lib/node_modules/appium/
But I was getting the same problem, finally after
npm cache clean
it worked !
I had the same problem and tried to fix the permission/ownership of npm related files and directories for hours but had no luck with that.
Suddenly I found that I had ~/.npmrc file with cache entry pointing to a non-existing directory. Removed that cache property to use the default cache location and now it's solved.
Disclaimer
I am a Windows user. However, my team and I have come across a number of issues regarding npm installaion errors.
Problems
The following is a list of lessons learned and a possible radical solution that has always rescued us:
node_modules, the npm local installation directory becomes protected from modification by a shortcoming of the OS such as the inability to process paths longer than 255 characters.
If the folder is erased by means of a command line tool it may still appear as if the folder exists in the explorer that when trying to access it gives a number of permission errors.
Depending on your antivirus and/or local policy manager you may be able to create the node_modules folder and later relegated access or permissions to it resulting in a number of installation errors.
Enable npm logs to gain further insight into possible problems with:
npm install --loglevel verbose
Radical
Install rimraf globally
npm install rimraf -g
Run rimraf on node_modules:
rimraf yourDir/node_modules
Then try running:
npm install
Warning!
Or lack there of. Be extremely careful about what follows the command rimraf. There are no warnings, no prompts, there is nothing. It simply erases the directory from the phase of the earth clean, as if it was never there. Try it at your own risk.
for me, it was my proxy... and make sure to delete package-lock.json.
this worked for me on my mac / unix based system:
npm config rm proxy
npm config rm https-proxy
npm config delete proxy
npm config delete https-proxy
npm config --global rm proxy
npm config --global rm https-proxy
npm config set registry "http://registry.npmjs.org"
npm config set strict-ssl false
npm install
run: scutil --proxy
you should get dictionary list...
then get these values from that list:
HTTPProxy : 127.0.0.1 HTTPPort : 8118
then include them in this command:
npm config set proxy http://127.0.0.1:8119
then include this:
npm config set https-proxy https://123.0.0.1:8118
reference: https://www.sneppets.com/angular/how-to-make-npm-install-command-to-work-behind-proxy/