Unable to install yarn through npm - npm

I am trying to install yarn through npm on Mac by referring the documentation given here: https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable
npm install --global yarn
However when I run this command in terminal, I am getting the following error and the package is not being installed
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
I also ran this command but nothing happened. I am also seeing messages like - this operation was rejected by your operating system. I haven't used yarn in a year, and everything was working fine, but suddenly I am running into all this. Would love to know what I am doing wrong here and how I can resolve this.
This the error message that comes
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.

sudo npm install --location=global yarn
This command worked for me

As warning messages indicate, global -global and -local appear to be deprecated. However, instead of global, you can use the -location=global command.
-global and -local is deprecated.
Use This command:
npm install --location=global create-react-app
Instead of:
npm install -g create-react-app

Related

How can I see all the 'npm WARN' that comes up after npm install?

I want to see the warnings that comes up after npm install, but without calling npm install. Is there a command I can use for that?
You can use npm install --dry-run to
report in the usual way what the install would have done without actually installing anything.
Npm install
You could also use npm audit for security warnings.
Npm audit

npm EACCES error again after fixing it

I was having an issue where I couldn't use npm to install things globally and I fixed it by following the instructions here and making a .npm-global directory. My computer restarted and updated software and now it doesn't work again and I redid the instructions but its not helping. Any idea what could be happening?
$ npm install -g express-generator
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied,
After following the instructions here like I said https://docs.npmjs.com/getting-started/fixing-npm-permissions it worked for a bit but then stopped working. What fixed it was resetting my prefix.
npm config set prefix ~/.npm-globall
The tip at the bottom is actually more useful.
"If you are using npm version 5.2 or greater, explore npx as an alternative way to run global commands, especially if you just need a command occassionally. Click here to read an excellent article about npx."
npx works great.
https://docs.npmjs.com/getting-started/fixing-npm-permissions

trouble installing an npm package

I'm trying to install react-navigation in a react-native app I'm working on and I keep getting this error....
Standard error:
npm ERR! code 128
npm ERR! Command failed: C:\John\Applications\cygwin\bin\git.EXE clone -q git://github.com/react-navigation/react-native-tab-view.git C:\Users\John\AppData\Roaming\npm-cache\_cacache\tmp\git-clone-e11f65d1 --config core.longpaths=true
npm ERR! fatal: Invalid path '/cygdrive/c/Users/John/AppData/Roaming/npm-cache/_cacache/tmp/C:\Users\John\AppData\Roaming\npm-cache\_cacache\tmp\git-clone-e11f65d1': No such file or directory
npm ERR!
I have no problem with other packages, and I have git and it works. I have npm and it works.
So far I've manually deleted cpm cache from C:\Users\John\AppData\Roaming\npm_cache. Ran npm i -g npm Deleted package-lock.json
But nothing is working. Any ideas?
Figured it out. For my case at least I have git installed via cygwin and have cygwin in my path. I guess for some reason this package doesn't like that?
But I uninstalled git from cygwin and then installed it the 'normal' way and then it worked.

Can't install "react native cli" globally by using git bash

When I type in "npm install -g react-native-cli" at git bash I get following errors:
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at: npm ERR! https://github.com/npm/npm/issues
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\TOSHIBA İ5\AppData\Roaming\npm-cache_logs\2017-10-19T04_04_05_774Z-debug.log
I have already installed npm and added it's directory to PATH variable and when i type "which npm" at git bash it shows the directory so there is no problem about the installation of npm. But it still gives these errors and I am stuck.
Note: I am following the instructions on https://shift.infinite.red/getting-started-with-react-native-development-on-windows-90d85a72ae65
This could happen in some npm old versions. Make sure you are using an updated one.
npm install -g npm
Some linux distros have old versions of npm and node on their packages and you need to install it manually.
Edit: I just saw you have windows. Nevermind, still the old version could be a problem.

Error: EPERM: operation not permitted, unlink 'D:\Sources\**\node_modules\fsevents\node_modules\abbrev\package.json'

I just updated npm to 5.4.0.
Now, Whenever I want install a npm package I get the following error:
D:\Sources\DownloadCms\Md.Download\Web.Angular>npm install mds.angular.datetimepicker#latest --save
npm ERR! path D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.json
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.json'
npm ERR! at Error (native)
npm ERR! { Error: EPERM: operation not permitted, unlink 'D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.jso
n'
npm ERR! at Error (native)
npm ERR! stack: 'Error: EPERM: operation not permitted, unlink \'D:\\Sources\\DownloadCms\\Md.Download\\Web.Angular\\node_modules\\fsevents\\node_modules\\ab
brev\\package.json\'\n at Error (native)',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'D:\\Sources\\DownloadCms\\Md.Download\\Web.Angular\\node_modules\\fsevents\\node_modules\\abbrev\\package.json' }
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! C:\Users\Mohammad\AppData\Roaming\npm-cache\_logs\2017-09-03T03_25_50_432Z-debug.log
I'm dead sure, run CMD as administrator.
Also I checked D:\Sources\DownloadCms\Md.Download\Web.Angular\node_modules\fsevents\node_modules\abbrev\package.json\, package.json is not exist in path !
Edit:
Upgrade to v5.4.1, still get the same error, even cannot work around with --no-optional :-(
I was able to fix this by running the command prompt/bash as admin and closing VSCode!
Seems like VSCode was locking some files.
Potentially something else could be locking these files for you.
It is an npm 5.4.0 issue https://github.com/npm/npm/issues/18287
Workarounds are
downgrade to 5.3
try running with --no-optional, i.e. npm install --no-optional
Please close all IDE like visual studio code. run npm install command through node.js command prompt.
Enjoy !
If you downgrade to 5.3 and still get the same error in Windows like me.
After hours working with npm versions I found the following solution:
1. Download latest recommended version of nodejs, these days is node-v6.11.3-x64
2. Uninstall nodejs with it.
3. Go to C:\Users\{YourUsername}\AppData\Roaming folder and delete npm and npm-cache folders
4. Run installer of nodejs again and install it
5 Update npm to 5.3 with npm i -g npm#5.3 command line
Now you should use npm without any issues.
I tried this solution found at a How to fix Node.js blog
just use
npm cache clean
in windows if it refuses use
npm cache clean --force
cache clean and npm update to latest with force work for me
npm cache clean --force
npm install -g npm#latest --force
I fixed by downgrading npm from 5.4.0 to version 5.3
npm i -g npm#5.3
I Hope this helps for you
I had the same problem on Windows.
The source of the problem is simple, it is access permission on folders and files.
In your project folder, you need
After cloning the project, change the properties of the folder and change the permissions of the user (give full access to the current user).
Remove the read-only option from the project folder.
(Steps 1 and 2 take a long time because they are replicated to the entire tree below).
Inside the project folder, reinstall the node (npm install reinstall -g)
Disable Antivirus. (optional)
Disable Firewall. (optional)
Restart PC.
Clear the npm cache (npm clear)
Install the dependencies of your project (npm install)
After that, error "Error: EPERM: operation not permitted, unlink" will no longer be displayed.
Remember to reactivate the firewall and antivirus if necessary.
I had the same issue and all I needed to do was login to npm
npm login
or alternatively
npm add user // consult the documentation for the params
For those who are coming from Windows OS, you just need to stop the development server and then execute your npm install ... command.
It is strange how Windows doesn't allow installing dependencies while server is running, but MacOS does allow.
If this doesn't work, then only go for the other options - clean cache, downgrade nodejs etc.
If all of the above failed to work for you, you might want to
restart your system
run command prompt as admin
run the npm command
In my case, the problem was that, I did not install typescript. Although I did install Node and Angular.
To check if you have installed typescript or not
Run this command: tsc -v
If not, then to install typescript
Run this command: npm install -g typescript
And, finally to install required dependencies
Run this command: npm install
in the root folder of the project.
---- Hope this helps someone ----
I had this logs in Windows.
I did the following
Close Visual Studio Code
Run Command Line as admin
Deleting package-lock.json fixed it for me.
I'm using VsCode and solved this issue by stopping the application server and them run npm install. There are files that were locked by the application server.
No need to close the IDE, just make sure there's no another process locking some files on your projects.
Mine was as a result of opening my project folder a 2 different terminals. I solved it by closing all running terminal (vs code was excluded) and executing the installation command again.
I hope this helps someone.
NB: deleting node_modules didn't solve it.
For me it worked in bash from git package
try:
C:\Program Files\Git\bin\bash.exe
then:
npm install mds.angular.datetimepicker#latest
There seems to be many solutions out there that worked with downgrading npm versions. For me, the solution was
npm install -force
I tried the downgrading of npm versions, modifying my npm prefix config to match the npm directory, and clearing cache. None of these worked, but apparently they worked for others, so it may be worth a shot.
For me on Windows the problem was too long path length. I moved the project to a smaller length path and it worked.
Deleting my node modules folder and running a normal npm install did it for me
For me it was Docker...
The moment that I closed the app container, I could do an npm install without any proble
P.S My node version is 14.15.5
I fixed this by removing the dist folder
--- Remove dist or public folder
the same error comes to me when i update the npm version to the latest 5.4
downgrade to the version 5.3.0 is useful.the error comes from the npm 5.4,you can check it in the issuses in npm 5.4
npm install npm#5.3 -g
Fixed in NPM 5.6.0
Upgrade to NPM 5.6.0 solved problem for me.
I wanted to run npm install from within my external hard drive as this is where i saved my code workspace. Windows 10 OS.
But I was getting the same error as the original post.None of the previous answers worked for me, I tried all of them:
uninstalling nodejs then re-installing
uninstalling nodejs then downgrading/installing a lower version of nodejs.
npm install -force
deleting the folders from C:\Users{YourUsername}\AppData\Roaming ... npm and npm-cache then re-installing.
npm cache clean --force
npm cache clean
npm install --g or npm install --global
What worked for me was this:
copy the folder from C:\Program Files\nodejs to D:\Program Files\nodejs
Then go to Control Panel\System and Security\System
Advanced System Settings
Environment Variables
System Variables
Double click Path
Add a new path
D:\Program Files\nodejs
Click ok
restart PC.
try npm install from within D: Drive
npm cache verify solved my issue.
I was doing: ng new my-app
and I faced similar error
I have
node version: 10.16.0
npm v 6.9.0
After trying everything, including node/npm upgrade, cache cleaning and reverting code, nothing helped besides one simple thing: Turning OFF Windows 10's Real-time protection during the dev/build. Looks like latest updates made it super aggressive.
npm login is required before publish
For windows,
Download latest recommended version of nodejs, these days is node-v6.11.3-x64
Uninstall nodejs with it.
Go to C:\Users\{YourUsername}\AppData\Roaming folder and delete npm and npm-cache folders
Run installer of nodejs again and install it
By default npm 3.10.10 should be installed along with node-v6.11.3-x64.
It worked for me with npm 3.10.10 but did not work with 5.3.X.
Also it did not worked with higher versions of node (above
node-v6.11.3-x64)
My problem was executing the command (npm audit fix all). I solved it when closing VSCODE and re-executed the command without problems.