How do I fix the npm install on Linux? - javascript

I'm trying to use npm install to install a package but I keep getting below error.
I tried updating and downloading again from root but nothing seems to work.
hackathonday1-2 git:(save-button) ✗ npm install file-saver --save
npm WARN checkPermissions Missing write access to
/home/salman/node_modules/axios npm WARN checkPermissions Missing
write access to /home/salman/node_modules/coffeescript npm WARN
checkPermissions Missing write access to
/home/salman/node_modules/coffee-script npm WARN checkPermissions
Missing write access to /home/salman/node_modules/file-saver npm WARN
checkPermissions Missing write access to
/home/salman/node_modules/materialize-css npm WARN enoent ENOENT: no
such file or directory, open '/home/salman/package.json' npm WARN
salman No description npm WARN salman No repository field. npm WARN
salman No README data npm WARN salman No license field.
npm ERR! code EACCES npm ERR! syscall access npm ERR! path
/home/salman/node_modules/axios npm ERR! errno -13 npm ERR! Error:
EACCES: permission denied, access '/home/salman/node_modules/axios'
npm ERR! [Error: EACCES: permission denied, access
'/home/salman/node_modules/axios'] { npm ERR! stack: "Error: EACCES:
permission denied, access '/home/salman/node_modules/axios'", npm ERR!
errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access',
npm ERR! path: '/home/salman/node_modules/axios' npm ERR! } npm ERR!
npm ERR! The operation was rejected by your operating system. npm ERR!
It is likely you do not have the permissions to access this file as
the current user npm ERR! npm ERR! If you believe this might be a
permissions issue, please double-check the npm ERR! permissions of the
file and its containing directories, or try running npm ERR! the
command again as root/Administrator.
npm ERR! A complete log of this run can be found in: npm ERR!
/home/salman/.npm/_logs/2019-09-24T03_37_30_909Z-debug.log

If there is a permission error on Linux for npm install, you can try to include sudo at the beginning of command. sudo npm install. Also make sure node.js is installed globally on your machine. Also make sure you have a package.json folder.

It's simply complaining about the fact that you don't own the folders /home/salman/node_modules/axios, /home/salman/node_modules/file-saver etc. Since it is your home directory, there really shouldn't be any directory or files that you don't own in /home/salman. My guess is that this happened because you ran npm with sudo causing it to create some files in your home folder that is owned by root instead of salman.
To fix the permission issue simply retake ownership of the node_modules folder:
cd /home/salman
sudo chown -R salman:salman node_modules
The -R flag makes chown recursively set you as the owner to all files and subfolders in the directory.
Side note: you really shouldn't use your home directory as your npm project directory. Do npm install in individual project directories. Yes, this wastes disk space but disk space is cheap and can freely be wasted. Even if you have 10 node.js projects you are unlikely to use more than 5GB of disk space even though there are lots of duplicate code files. A single HD movie is sometimes larger than that. Typical disk space usage for code is around 2GB.

sudo chown -R $USER /home/salman/node_modules
This command is useful.. Run it on your system..

Related

npm install errors out preinstall script

I needed to fix security vulnerabilities for knexnest > knex > minimist. The version for minimist did not get updated with npm audit fix or simple npm update. I followed this article and it updated the versions and gave a vulnerability score of 0. But now when I create a docker image (build) my repo, it fails at the preinstall script.
npx: installed 5 in 5.29s
EACCES: permission denied, open './package-lock.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-service#1.2.3 preinstall: `npx npm-force-resolutions`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-service#1.2.3 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/node/.npm/_logs/2020-07-15T09_56_56_625Z-debug.log
While installing modules locally on editor, no errors pop up. Please help!
I had the same error, I fixed it with
chmod 666 package-lock.json
This doesn't seem as a root cause solution, but it's a simple workaround.

Bcrypt refuses to install; no fixes have worked yet

This has been months worth of troubleshooting. I cannot npm install bcrypt no matter what I try.
I've tried sudo npm install bcrypt, brew install bcrypt, uninstalling node and reinstalling node, copying bcrypt files and editing my json files... Nothing works. Tested with alternatives to bcrypt, such as bcryptjs. This is only a problem with bcrypt packages, and I have tried dozens of suggestions and solutions I've found online to no avail.
Brew tells my bcrypt is installed, so I uninstall it through brew and it says it is still installed. I've done npm uninstall bcrypt -g just in case, but it still doesn't work. It says I don't have access to my node_modules folder, but, again, this only happens with bcrypt and literally nothing else. Express, postgresql, cors, body-parser, react, redux, thunk... Everything else installs and works without any issue.
npm WARN checkPermissions Missing write access to /Users/someUser/Desktop/realtorSite/server/node_modules
npm WARN server#1.0.0 No description
npm WARN server#1.0.0 No repository field.
npm ERR! path /Users/someUser/Desktop/realtorSite/server/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/someUser/Desktop/realtorSite/server/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/Users/someUser/Desktop/realtorSite/server/node_modules'] {
npm ERR! stack: 'Error: EACCES: permission denied, access ' +
npm ERR! "'/Users/someUser/Desktop/realtorSite/server/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/someUser/Desktop/realtorSite/server/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/someUser/.npm/_logs/2019-06-16T22_38_43_256Z-debug.log
I just want to figure out what is wrong and be able to regularly use bcrypt and other encryption-based packages.
https://lightrains.com/blogs/fixing-npm-permissions-install-global
This link is how I fixed my issue. First, I used npm config get prefix to find my npm directory and cd ~ to get to my root directory. I then ran ls -a and found a node_modules folder in my root. By using ls -la node_modules, I found root was given all permissions by I had no rights. sudo chown -R someUser node_modules changed all permissions inside of node_modules to someUser instead of root.
Tested npm install bcrypt and it installs without issue.

create-react-app newproject commandline is not working for me

for some reason ive been ending up with "command not found" when i type in the create-react-app newproject command. Its been giving me this error:
npm WARN checkPermissions Missing write access to /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
npm ERR! path /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app'
npm ERR! { Error: EACCES: permission denied, access '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/Users/kennyquach/.npm-global/lib/node_modules/create-react-app\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kennyquach/.npm/_logs/2018-11-28T17_50_32_739Z-debug.log
any help is appreciated! Thanks!
As the error clearly shows you dont have write access to /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
try changing access to 777 for all of .npm-global folders and then give a try.
You are high likely using Mac OS as Operating System. This is a general issue of globally installed packages in MacOS that caused by built-in node application's file permissions. Actually you can get over this by executing create-react-app as root, but i don't recommend that, it's not useful and it's risky.
So you got 2 options. (First one is hard to do, second is blazing fast)
1-) Completely remove Node from your System and install it with Brew. You can easily update node with that package manager and install any other popular developer tools too (Like: mongodb, mysql, pgsql, rabbitmq etc.).
You can get brew from here: https://brew.sh and install node with that code: brew install node
2-) You can easily give read, write, execute access to your folders and files. You can do it like this: sudo chmod -R 777 /Users/kennyquach/.npm-global/ when sudo asks your password, use your Administrator password.
This looks like an access issue. I faced same issue in MAC OS X, when I tried running the command with sudo, it worked for me.
sudo npm install -g create-react-app

Command not found

Been struggling to get my first vue project started and was looking for some help.
I have both npm and node updated on my system but continually keep falling to the same issue.
My steps:
1.) npm install
Terminal Response:
npm WARN mbasile#1.0.0 No description
up to date in 0.095s
2.) npm install vue
Terminal Response:
npm WARN mbasile#1.0.0 No description
+ vue#2.5.16
updated 1 package in 0.951s
Here's where things get funky?
3.) npm install -g #vue/cli
Terminal Response:
npm ERR! path /Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir
npm ERR! Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'
npm ERR! { Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rmdir',
npm ERR! path: '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin' },
npm ERR! stack: 'Error: EACCES: permission denied, rmdir '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rmdir',
npm ERR! path: '/Users/mbasile/.npm-global/lib/node_modules//node_modules/.bin' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mbasile/.npm/_logs/2018-05-09T17_53_06_030Z-debug.log
So given this response I run
4.) sudo npm install -g #vue/cli
Terminal Response:
/Users/mbasile/.npm-global/bin/vue -> /Users/mbasile/.npm-global/lib/node_modules//bin/vue.js
+ #3.0.0-beta.9
updated 1 package in 6.597s
5.) vue create vue-project
Terminal Response:
-bash: vue: command not found
Leaving me a bit puzzled and confused here, but any help/response would be appreciated.
I had this problem too and it was a little bit tricky to find a solution so I'll describe all the steps that helped me find a solution.
It's resolving a general problem with the wrong path for global packages in npm or missing path in shell variable $PATH.
Fix for macOS Mojave but should work on all UNIX systems
First of all, after installing the package globally npm will show you where a new package is installed.
$ npm i -g #vue/cli
/usr/local/Cellar/node/9.5.0/bin/vue -> /usr/local/Cellar/node/9.5.0/lib/node_modules/#vue/cli/bin/vue.js
We can also check it in the npm config.
$ npm config get prefix
/usr/local/Cellar/node/9.5.0
So if after the global installation your terminal couldn't recognize the command it's probably missing in your shell variable $PATH. You can easily check it.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
As we can see, the path from npm config isn't present in the shell variable $PATH.
Now we have two options to fix it.
1. First option - change npm config.
$ npm config set prefix '/usr/local'
$ npm config get prefix
/usr/local
After we changed the path in the config we will have to reinstall the desired package.
$ npm i -g #vue/cli
2. Second option - add path from npm config to shell $PATH
$ export PATH=$PATH:/usr/local/Cellar/node/9.5.0
In this case, we don't need to install the package again.
Regardless of the selected option, we can now control if everything works.
$ vue --version
3.0.5
Maybe it is something wrong with npm
I recommend you,first list all global npm packages to see if vue is installed with the command: npm list -g --depth=0
Then if vue is installed but again you get error try to delete vue with the command: npm uninstall -g nameOfPackage
Finally do it again from scratch: npm install -g #vue/cli and to create new project,navigate to directory you want to create the project and execute: vue create nameOfProject
What are you trying to do?
npm install -g #vue/cli
This is the command you should run on terminal to globally (-g) install vue command line interface.
After that you can do vue create vue-project

npm install / bower install issue and deprecated modules with angular-phonecat setup

I am trying to run npm install on my terminal as part of the setup for angular-phonecat as per the instructions on https://docs.angularjs.org/tutorial
When I run the command I am getting issues with deprecated modules and errors when reaching the bower install section.
Does anybody know how I can update the deprecated modules to avoid the warnings and how I can fix the bower errors?
Here is the output I am receiving:
npm WARN deprecated tough-cookie#2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated minimatch#0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
-
> fsevents#1.0.14 install /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/karma/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build
[fsevents] Success: "/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/karma/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> angular-phonecat#0.0.0 postinstall /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat
> bower install
bower EACCES EACCES: permission denied, unlink '/Users/Eamon/.cache/bower/registry/bower.herokuapp.com/lookup/jquery_d223e'
Stack trace:
Error: EACCES: permission denied, unlink '/Users/Eamon/.cache/bower/registry/bower.herokuapp.com/lookup/jquery_d223e'
at Error (native)
Console trace:
Error
at StandardRenderer.error (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/renderers/StandardRenderer.js:81:37)
at Logger.<anonymous> (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/bin/bower.js:110:26)
at emitOne (events.js:77:13)
at Logger.emit (events.js:169:7)
at Logger.emit (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/bower-logger/lib/Logger.js:29:39)
at /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/commands/index.js:48:20
at _rejected (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:844:24)
at /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:870:30
at Promise.when (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:1122:31)
at Promise.promise.promiseDispatch (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:788:41)
System info:
Bower version: 1.7.9
Node version: 4.4.0
OS: Darwin 15.6.0 x64
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.4.0
npm ERR! npm v2.14.20
npm ERR! code ELIFECYCLE
npm ERR! angular-phonecat#0.0.0 postinstall: `bower install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-phonecat#0.0.0 postinstall script 'bower install'.
npm ERR! This is most likely a problem with the angular-phonecat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! bower install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular-phonecat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls angular-phonecat
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/npm-debug.log
I have tried searching on other posts with similar issues but none of these have helped me find a solution:
error when npm install
Got an error while running "npm install" on angular-phonecat directory
Cannot npm install for angular-phonecat tutorial : Cannot find module 'update-notifier'
I have also tried running sudo npm install with the same issue. I have a feeling the bower install issues are due to the setup of the bower cache looking at the error output but I am not 100% certain.
Has anyone encountered similar issues when setting up the installation for angular-phonecat?
Any help would be greatly welcomed.
Many Thanks,
Eamon
ISSUE: You (the user) don't have the right set of permissions for the directory.
The instant way out is to run the npm install using sudo, but this may give you the same error, or improper installation.
AND changing directory ownership is not a good option, a temporary patch. I am answering the question, as I feel I have a more elegant solution/suggestion to the problem. I came across same issues multiple times i.e. 'npm install -g #angular/cli'.
Uninstalled the package and executed the following commands (in the order mentioned) to have clean installation.
Solution/Suggestion: Change npm's Default Directory (from official docs)
Back-up your computer before moving forward.
(optional) In case you have a erroneous installation, first uninstall it:
npm uninstall <package-name> # use sudo if you used it while installation
npm cache verify # or, npm cache clean for npm version below 5.x.x
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile or ~/.bash_profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables, or restart the terminal:
source ~/.profile
(optional) Test: Download a package globally without using sudo.
npm install -g jshint
Having looked into this it appears that bower was having issues with permissions and was resolved by running the bower install separately using sudo:
sudo bower install --allow-root
However, you should not use sudo with bower. It is likely that if you have to then the ~/.cache has been set incorrectly either by installing using sudo or installing your first package via sudo. More info about this can be found here: http://www.competa.com/blog/2014/12/how-to-run-npm-without-sudo/
Instead you should rectify the ownership by running the following:
sudo chown -R $user ~/.npm
sudo chown -R $user ~/.config
To find your user you can simply run the following command on the command line:
$ whoami
If you want to open to a wider group you can also add a group to the chown command. To find out which group your user belongs to you can type the following command:
$ groups
To set the group at the same time as the user simply change the command to the following and replace $user and $group with your desired user and group:
sudo chown -R $user:$group ~/.npm
sudo chown -R $user:$group ~/.config
If you are seeing an issue like one of the below when running a bower install during your npm install:
EACCES: permission denied, open '/some/directory'
EACCES: permission denied, unlink '/some/directory'
You will need to change the permissions to the folder containing the file to be your user by doing:
sudo chown -R USER /some/directory
Just change the folder that the file is stored in, not the file itself. When you run npm install after this it will work if it needs to install any bower components that are having issues installing while using your current user and not using sudo.
Thanks,
Eamon

Categories

Resources