npm install no longer possible after deleting module directory - node.js

So I wanted to help out, and forked a Node-RED module to make some small contribution, but then got lost messing around with how to get Node-RED to run my fork (for testing) rather than the packaged version. Then I learned about npm's ability to install from a Github URL, which is nice, but it wouldn't work because I had already installed the module. Then I found I couldn't uninstall it either
npm uninstall original-module
npm ERR! path /home/nodered/.node-red/node_modules/original-module/package.json
npm ERR! code ELOOP
npm ERR! errno -40
npm ERR! syscall open
npm ERR! ELOOP: too many symbolic links encountered, open '/home/nodered/.node-red/node_modules/original-module/package.json'
so in frustration I deleted the module's directory, only to find myself unable to move forwards, or backwards. npm install https://github.com/me/forkedmodule fails with
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master https://github.com/me/forkedmodule.git /root/.npm/_cacache/tmp/git-clone-d31dc53b
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-d31dc53b': Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_07_18_257Z-debug.log
and trying to install the original with npm install original-module fails with
npm ERR! code ENOLOCAL
npm ERR! Could not install from "node_modules/original-module" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-08-22T01_09_56_127Z-debug.log
As you've probably guessed, I'm pretty new to Node.js, Node-RED and npm, but I haven't been able to help myself, so have to ask for help! It seems nonsensical to me that npm appears to be looking for a local copy of the package.json file belonging to the package I'm trying to install?
Edit: I should add that the above commands were all run as root.

Ok, found a solution, not sure if it's the best one though!
In the "project" directory (/home/nodered/.nodered in my case) there's a package-lock.json file which lists the packages used by the project. In there I found an entry for the original-module which I removed, after which I was able to install the package "normally" with npm install original-module.
Then to solve the permission issue when installing from a GitHub URL, I found I needed to impersonate the "nodered" user with su - nodered (it's a password-less user in my case). As "nodered" npm install https://github.com/me/forkedmodule succeeded without any error. A little curious since I was trying to do this as root before, and got a permission error, but there you go. I also took the opportunity to chown -R the project's node_modules directory to nodered:nodered as I could see that was a bit of mess.
In future, I will try to remember to su - to my nodered user first, and navigating to the project root (again, /home/nodered/.node-red in my case) before running npm install anything. Hopefully that will avoid any further issues. Oh and a note to anyone else who just wants to contrib some quick changes to a module hosted on GitHub: to "pull" in changes you simply run npm install https://github.com/me/forkedmodule again - npm doesn't appear to provide any dedicated "update" method.

I had the same issue, in my case the solution was to delete the package-lock.json, delete node_modules, then reinstall npm modules.

Related

npm install not working. Says that I need to check permissions?

I'm trying to install eslint on my machine right now but it is saying that I need to check permissions because its missing write access to /user/local/lib/node_modules. Does anyone know how to fix this? Thanks!
npm install -g eslint
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
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/mkaplan/.npm/_logs/2019-03-03T18_05_46_487Z-debug.log
Try sudo npm install -g eslint
For Linux use sudo npm install and
For Window run powerShell as administrator and got to directory of project and run npm install
In my case I had this same problem to install angular, so just change the command to :
$ sudo npm install -g #angular/cli
This kind of stuff happens when you run npm commands with sudo to begin with. So don't do it?
If this happens, it means that someone has been messing around npm as root. Then root took and created files in global npm cache, denying access to anything different than root.
This is why it fires EACCES when running npm install or npm install -g
You are not supposed to do anything related to node_modules nor runnpm [anything] with sudo. Do you understand that you are giving the package in question permission to do whatever it wants? Even if you check the package and ensure its security yourself, what about dependencies it downloads? will you check them as well?
npm registry gets 30b weekly downloads, their malware control is nowhere near enough
You are giving away access to whole sys folder tree to the files of the package in question. Even npm itself gives you feedback that it is not recommended. You do not know what package does in the background. What if you install a package i developed, but i am a villian who likes to make people's life harder... This is a security issue.
The above story apart. If you do it with sudo, this will force you to run certain npm commands as sudo from that point on, messing it up even more.
The maximum you do as root in this case, is give access for node_modules to whoami
The best solution is to either set it up properly so you dont have to use sudo or run app in container, so anything you do is executed inside container, not affecting your local machine at least. Even there it is not recommended to mess around as root, permissions get so messy... it's a hell to debug.
I'm fairly new to Node but as a longtime Linux user I'not sure installing node packages as root (via sudo) is a good idea.
I imagine eslint is fine but if you're having this issue installing one package then I'm guessing you're having the same problem with every package you're installing globally ('-g'). That means that every time you install a package from npm globally you're downloading who-knows-what install script and running it with root privileges on your computer.
Anyway, as I said I'm no Node expert but I had this same problem and my issue was that I'd installed the "nodejs" package using apt. If this is what you did then I suggest:
Remove nodejs with sudo apt remove nodejs. (Depending on what Linux distro you're using this may be different. I'm running Ubuntu.)
Install nvm or some other node version manager as recommended by the NPM docs.
When I did this, I was able to install NPM packages globally without sudo.
(Yes, I'm telling you not to install things by running npm as root and then saying you should install things by running apt as root. But you definitely need to run apt as root and I know appropriate precautions are taken by the apt devs and Ubuntu package repo managers. I'm not 100% sure it's wrong to run npm as root but I'm not sure it's right either, and I was able to avoid running it as root using the above steps.)
This can solve the problem:
sudo npm install -g npm
First try sudo npm install -g gatsby-cli
then npm start
I ran into an issue trying to install truffle and got the following errors:
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
I was able to solve this issue with the recommendation to add 'sudo'.
solution:
sudo npm i -g truffle
Use the command:
sudo npm install -g eslint
With the sudo command you will have the permission to install.
This might happen when you just "sudo" everything in order to make it work or you install a dependency forcefully , you should not mess with the root folder of node modules.
For now you can try installing using
sudo npm install -g eslint
Use this npm install node-sass --save

How can I install `bcrypt-as-promised` from an old code base onto my ubuntu box?

I'm working with an old code base from an old project that uses bcrypt-as-promised (before bcrypt allowed the use of promises). When I try and npm install the package.json, I receive this error for that package:
npm WARN deprecated bcrypt-as-promised#1.1.0: the bcrypt module supports promises now, this module is no longer necessary
npm WARN deprecated bcrypt#0.8.7: bcrypt < v2.0.0 is susceptible to bcrypt wrap-around bug. Upgrade to bcrypt >= v2.0.0 for improved support for newer bcrypt hashes
And then proceeds to fail (I can paste more of the error message if needed).
I'm a little confused as to how I might be able to get this now deprecated package to install. I thought about modifying the codebase to only use bcrypt (with the now native promises supported), but I'm afraid of diving into a bee's nest and breaking the application. I was wondering first if there might be a way to install this package for the old code base to get it working.
Any thoughts? Thanks for your time and any insight you may have.
My package.json: https://github.com/twknab/mean_hike/blob/master/package.json
// Edit:
Here's the full terminal message I receive when I try and sudo npm install:
> bcrypt#0.8.7 install /var/www/mean_hike/node_modules/bcrypt
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir
'/var/www/mean_hike/node_modules/bcrypt/build'
gyp ERR! System Linux 4.4.0-1072-aws
gyp ERR! command "/usr/local/bin/node"
"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/mean_hike/node_modules/bcrypt
gyp ERR! node -v v11.2.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt#0.8.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt#0.8.7 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ubuntu/.npm/_logs/2018-11-27T10_46_27_925Z-debug.log
Older versions of bcrypt can be quite tricky to install, and it looks like you're hitting a classic permissions issue with npm. You can try some of the tips listed in the official documentation here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
… but in the meantime, here are a few things to try:
Attempt a global install of node-gyp first, either with or without
sudo: npm install node-gyp -g
If that works, then try installing
bcrypt (again, globally).
If you're still seeing permissions issues,
you may need to sort out ownership of your node_modules directory:
sudo chown -r XXX /usr/lib/node_modules/ (assuming that's where
the global modules directory is on your machine of course).
I found a solution to my issue was to use yarn to import all of my dependencies rather than npm, while also swapping bcrypt-as-promised for bcrypt (which now includes promises with no syntax changes necessary).
I ditched bcrypt-as-promised and replaced it with bcrypt in my package.json file.
I then changed any instance of require('bcrypt-as-promised') to require('bcrypt') (the syntax for using bcrypt remains the same, just the dependency importation lines need to change).
Without using yarn, even after changing my folder permissions, I was still hitting permissions "EACCES: permission denied" errors, with only bcrypt failing. My versions of npm and node seemed fine. Made sure my Ubuntu box was all updated.
That's when I gained the suggestion from a wise friend to try using yarn to grab the dependencies instead. I ran yarn import which reads the package.json file and creates a yarn.lock file. I then installed yarn on my ubuntu machine (sudo npm install yarn -g), and ran yarn install, and bcrypt successfully installed!
Update Jan 2019 - Improved Solution
It looks like if npm dependencies were originally installed using sudo, permission issues can be experienced when trying to install bcrypt. My improved solution was to:
Nuke the ./node_modules folder via sudo rm -r ./node_modules
Install npm packages fresh (not using sudo).
After this, I was able to npm i --save bcrypt with the package installing
successfully.
Here's a link from GitHub that helped me find the solution and an excerpt:
#Mayocampo permission denied, mkdir
'/home/someroute/node_modules/bcrypt/build'
It seems you run rpm as root, therrfore your account cannot mkdir
under /home/someroute/node_modules/ Check dir with ls -l
/home/someroute/node_modules/ Im sure owner of upper dir is root. or
your account cannot have permission.
I guess there are two options are available.
sudo rm -r ./node_modules And install package via npm
again, but without using sudo.
Change mod ./node_module to access and excutable. I decided first, and its fixed
Source: juicycool92 # GitHub

Polymer CLI - npm error code 1

I get this error when trying to install polymer CLI. I keep on getting this whenever i try to install it.
sudo npm install --unsafe-perm -g polymer-cli
Password:
npm WARN deprecated bower#1.8.0: ..psst! While Bower is maintained, we
recommend Yarn and Webpack for *new* front-end projects! Yarn's
advantage is security and reliability, and Webpack's is support for
both CommonJS and AMD projects. Currently there's no migration path but
we hope you'll help us figure out one.
npm WARN deprecated #types/assert#0.0.29: See
https://github.com/DefinitelyTyped/DefinitelyTyped/issues/12826
npm ERR! code 1
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master
git://github.com/polymerelements/test-fixture.git
/Users/litsonthomas/.npm/_cacache/tmp/git-clone-eddd277b
npm ERR! /Users/litsonthomas/.npm/_cacache/tmp/git-clone-eddd277b/.git:
Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/litsonthomas/.npm/_logs/2017-06-22T17_39_34_600Z-
debug.log
I am new to polymer and I don't know where am getting wrong!
This seems to be a pertinent issue in this package (issues in the repository: #784 #800). You have to go to the npm site on Fixing npm Permissions and follow the steps there.
You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.
You can fix this problem using one of three options:
Change the permission to npm's default directory.
Change npm's default directory to another directory.
Install node with a package manager that takes care of this for you.
Whether you should follow one of the three options depends on each particular case. What I would recommend first is to try changing the npm default directory to some place with user read/write permissions. Then, you should start doing npm i -g without sudo.

npm install error code EBUSY errono -4082

I am running windows7 and have just installed the following...
c:\design_centre_dev\workspace>node -v
v5.10.1
c:\design_centre_dev\workspace>npm -v
3.8.6
I'm having issues running npm install on my node project which one of my fellow dev's says he has no trouble with and should work for me.
When I run npm install i am getting errors like...
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Users\\rriviere\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v5.10.1
npm ERR! npm v3.8.6
npm ERR! path c:\design_centre_dev\workspace\node_modules\path-type
npm ERR! code EBUSY
npm ERR! errno -4082
npm ERR! syscall rename
npm ERR! EBUSY: resource busy or locked, rename 'c:\design_centre_dev\workspace\node_modules\path-type' -> 'c:\design_centre_dev\workspace\node_module
s\.path-type.DELETE'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
It seems to throw these same types of errors for modules asynch,path_type and isarray and does not want to get past them.
Can anyone suggest what might be wrong?
EDIT
Thanks for the suggestion of this thread possibly being answered somewhere else. I had a look and I believe it is a different problem. I think this because I've been investigating further today and I think the problem is that the node_modules directory which npm is creating. The permissions on that directory don't seem to be right. I think this might be an issue and probably a new thread so I'll close this one and create a new.
If you have open that node module file in your editor then just close the file from the editor
Or
Close Editor Software
Then Try again
The cause of this was windows permissions problems. My work computer did not have privilleges to do certain things. When I moved to my personal mac everything just worked.
I got this error when tried to uninstall/re-install a module on Win10 VM. "npm cache clean", as suggested by some, did not work. Restarting the system resolved the issue.
This issue may links to country boycott or computer limitation. I live in a country which is boycott and I could rise that with turn on VPN and then do the process of installation. Please follow this:
npm run cache clean ---force (remove node_modules)
Turn on VPN (set it based on country which isn't boycott)
npm install
I met the same problem today. I found that is because I npm run in a terminal and npm install in another terminal. The file was occupied. I just delete the node_modules and npm run again.
This is an underlying issue of Anti Malware software blocking your application from connecting to node package manager (npm).
I am using Bullguard and disabling my Antivirus seemed to do the trick!
I was facing the same problem for 3 days and got this solution for it...
It's because of old files lying in your c drive:
Follow the steps below and try, It will work for sure.
problem:
npm ERR! Errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘scandir’,
solution:
Uninstall node with node uninstaller ( find it from run cmd )
Then...
Delete the npmrc file and delete the C:\Users\Administrator.npmrc file ( if don't find leave it )
Delete npm-cache folder from - C:\Users\Administrator\AppData\Roaming
Delete npm folder from - C:\Users\Administrator\AppData\Roaming
Restart your system and install fresh NodeJS and run this command in cmd: npm cache clean -–force to ensure the cache is cleared.
That's your ready to go now...
If you still face a problem feel free to get in touch with me #ishaiknadeem username on any platform
Just close the terminal and turn on a new one, then 'npm install' it works on me.

Fail to install npm package "npm ERR! errno -4048"

I'm trying to install npm package (node-xmpp-server) but it fail to install. previously when I'm trying to install a package that is install globally instead of locally, but now it's not installing at all. Plz Help me.
npm install node-xmpp-server
error is: npm ERR! errno -4048
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "c:\Program Files\nodejs\node.exe" "c:\Program
Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "node-xmpp-server"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! path c:\Users\Jaseem Abbas\Documents\node_modules\node- xmpp-server\examples
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! Error: EPERM, unlink 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples'
npm ERR! at Error (native)
npm ERR! { [Error: EPERM, unlink 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples']
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! path: 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples' } npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EPERM, unlink 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples'
npm ERR! error rolling back at Error (native)
npm ERR! error rolling back { [Error: EPERM, unlink 'c:\Users\Jaseem
Abbas\Documents\node_modules\node-xmpp-server\examples']
npm ERR! error rolling back errno: -4048,
npm ERR! error rolling back code: 'EPERM',
npm ERR! error rolling back path: 'c:\Users\Jaseem Abbas\Documents\node_modules\node-xmpp-server\examples' }
Kill whatever process is locking your files
It seems like this kind of error can be caused by a file permissions lock - I experienced something very similar (the same ERRNO: -4048) when installing whatwg-fetch.
I found that a Visual Studio instance I had open at the same time was acquiring all kinds of files which it didn't need. Once I closed that down, the install worked perfectly.
This may be a quickly-checked possible cause to eliminate before moving on to more drastic measures...
if you still have troubles with this error and maybe you upgrade the node version to 5.4 > ... that version presents an error. here the solution that basically consist in downgrade node version
In Windows will be:
npm install -g npm#5.3
That's works for me.
I was having the same problem and I found the following solution:
remove both of
%ProgramFiles%\nodejs\npm
%ProgramFiles%\nodejs\npm.cmd
Go into %ProgramFiles%\nodejs\node_modules\npm and copy the file named npmrc in the new npm folder, which should be %appdata%\npm\node_modules\npm. This will tell the new npm where the global installed packages are.
Restart Windows and it worked.
Found this over here (the npm troubleshooting section). Credits to the authors there
It seems that this error can manifest for more than one reason, so there probably won't be a single fix which works for everyone.
However, concurrency issues often are the cause of the failing installs. According to the accumulated wisdom in one of the related npm issue threads, which has received nearly 180 comments so far, the underlying problem is
a race condition between asynchronous I/O operations accessing the same files on the harddisk. You can certainly influence it by cleaning up the harddisk e.g. with "npm cache verify" or moving the project to a SSD, but this does not solve the root cause of the problem.
Likewise, closing the IDE or disabling the virus scanner works sometimes, for some people, but does not really fix the problem for good if concurrency issues are behind it.
A patch has landed in npm 5.6.0. According to initial reports, it seems to do the trick. So if your npm --version is lower, update to 5.6.0 (or whatever the current version is when you read this):
npm uninstall -g npm
npm install -g npm#5.6.0
as suggested here.
If that doesn't help, then perhaps a file lock is the true cause. And closing the IDE, or disabling the virus scanner temporarily, or some similar action is indeed the way to go, as #Oly has said above.
Had the same issue
Closing visual studio solved the problem
Upgrade npm to 5.4.2 it will fix this problem.
Command to install : npm i -g npm#5.4.2 or npm i -g npm
if still doesn't work try clearing cache using npm cache clean
you can use force like this npm cache clean --force
Someone said it was due to npm bug https://github.com/npm/npm/issues/9696
Adding "--force" to install allegedly works around the problem.
For me #Oly's solution worked, I'll just add for Angular folks that it was ng serve -o that had locked the files. Yep - don't run npm install while ng serve is running for the project.
I had this same problem, after setting up node.js I followed parts of a guide intended for unix and ended up moving my current working directory to a new folder, but I forgot to copy the .npmrc file from the old location to the new one. I also changed the location of my prefix away from %AppData%, which I found by using npm config ls -l to compare my current settings to the default. The two clues here were that I had a line at the start called userconfig pointing to my .npmrc file, which was in a different location, and that my prefix was overridden from the default value. Changing this back to the default fixed the problem.
Try resetting these to the defaults and check what your config settings are. I'm not sure if reinstalling node.js would help anything if it was still referencing your old settings.
I tried following solutions, I don't know which one worked for me.
Ran reactive-native init in command prompt as Administrator (on Windows OS), hoping works well with sudo reactive-native init on Mac OS
Ran npm cache clean command in Command prompt.
Disable your antivirus for time being.
Try any of the solution or all,
This is a long standing issue with npm that they seem to have no interest in fixing. Various things others are mentioning will work sometimes (e.g. closing running programs, downgrading the version, etc...). It's been generally limited to Windows installations, though I've even had it happen a bit in Linux lately as well.
np init
This will create a dummy package.json.
Open the file and enter your required dependencies list.
Now go for:
npm i
This fixed the problem for me.
In my case fetch same issue. Then first I stopped npm run watch then try again then it works.
Do the followings. This might be permission issue.
Uninstall all antivirus program and restart system
Install yarn
Delete package.lock.json and node_modules folder (if any)
Clear the cache (npm cache clean --force)
Close VS code or other code editor tool (If opened)
now run yarn install
This should resolve the issue.
I had this same issue, and determined that it was caused by having link-sharing enabled for the Google Drive folder that my project was in. Once I moved it to a non-link-sharing folder everything worked fine.
In my case, I right clicked the json file that was mentioned in the error, Unchecked the read only flag, and it worked
If you have XAMPP server running in the background, kill it.
Then run the installation again.
Worked like magic for me
I had the same problem...here is the fix:
install nodejs in your local directory that does not need admin privilege.
I changed the npm version and this did not happen again
I just run npm cache clean, and worked for me
Delete package-lock.json
and try again

Resources