87

I am having problems installing new npm packages with Yarn. Every time I go on to add a new package it's throwing me this error. But when I delete my node_modules folder and run Yarn, everything works fine. Again when I try to add another package, it throws me the same error. Any solutions, I am having a headache right now.

enter image description here

1
  • Got the same issue when using mklink (symlink) node_modules directory in Windows
    – LennyLip
    Commented Mar 25, 2021 at 5:59

22 Answers 22

297

In Windows first stop the development server and then try to install package.

6
  • 13
    What do you mean by development server? Need more details.
    – Abdollah
    Commented Dec 13, 2020 at 17:12
  • If strapi is working, stop it then update the packages Commented Feb 4, 2021 at 11:11
  • 2
    Development Server -> e.g. if you have a react project running. If you have, stop it.
    – Jan
    Commented Jan 19, 2022 at 16:48
  • 3
    Just in case someone needs it: in my case neither stopping project, nor running vscode with admin writes worked. In fact, both were done from the very beginning. The only thing that worked was to close vscode and open git bash in a target folder and then running that command in the target folder. Commented Feb 22, 2023 at 16:11
  • 1
    If you're using Angular --watch, need to kill that as well (close the terminal) Commented Mar 25, 2023 at 13:56
37

I had same problem, I went into the Task Manager (CTRL+SHIFT+ESC) and killed all the NodeJs processes.

16

Press "Ctrl+C" to stop the server and repeat the installation.

0
7

if you're using visual studio code, cmd, or Windows Terminal, close it and run it in administrator mode. Usually, the reason for that error message is a result of limited privilege giving to the editor or npm or Yarn if you're using that.

5

This is likely due to you creating your project within the windows /mnt directory structure

Rerun inside the ~/home folder

(accessible within windows @ //wsl$/

2
  • 2
    This was the correct issue in my case, but I'm curious why? What is special about the /mnt directory with regards to my permissions that causes this issue? Commented Jul 18, 2022 at 3:48
  • I have tried every other solution, this is the only one that worked. Note: install process was also orders of magnitude faster than on the mount.
    – szelesaron
    Commented May 29 at 10:33
4
  1. Stop the all-running server(project) using ctrl + C.
  2. Then run yarn

It should be working..!

3

did you try to open CDM as run as administrator or if with wsl terminal try to use sudo like sudo yarn

3

Restarting the system which causes stopping all the processes by Node, VScode, ... solved the problem for me.

2

I have this problem all the time with IntelliJ IDEA.

It seems Node Processes keep running in the background and block the installation.

Some of the candidates are

  • @esbuild
  • @swc
  • @nx

Maybe some are intended to run in the background, but I wish yarn could kill them at least on installation.

As a solution, I go to the Task Manager and kill all node processes within the IntelliJ IDEA group on Windows

enter image description here

1

Terminate or stop the server ( close and reopen Vscode) and try agin. this will work for me !!

1

The package I was trying to install before haveing this issue was yup. So resulted to

yarn add yup --legacy-peer-deps 

which worked.

1

What worked for me is stopping the development server, closing VS Code, deleting node_modules and running the yarn command with administrator rights.

2
  • Worked fine for me also
    – Abayomi
    Commented May 20, 2023 at 0:36
  • the issue with this is that after build, I have to remove again node_modules and re-install without admin rights, looking for a "real solution" and more practical for this bug :( Commented Feb 22 at 20:43
0

Sometimes when this occurs, you may first try to uncheck node_modules folder to read only. If it is not working try to stop the running server and install your packages and then restart the server.

0

Option No - 1: You can install that package with "npm" instead of "yarn"

Option No - 2: press "Ctrl + C" to stop running server and then install again.

0

If you are still facing the problem and you are using VS Code, try this way

  1. Close your VS Code

  2. Back to home

  3. Right click on VS Code icon

  4. Click on 'Run as administrator' and allow permission

  5. Then navigate to your project directory and try again

0

It seems that VScode block something by its internal process, it might be an extension like language service, or jest process, so if you want to get rid of affecting by VScode internal processes - you can just use external terminal, or open vscode new window and put bash to editor area. It works for me.

enter image description here

enter image description here

0

In my case, this was because Virtualbox client host-shared filesystem default didn't allow symlink.

The solution is to allow symlink feature for the filesystem which is shared between virtualbox client and host by:

$ VBoxManage setextradata <client-name> VBoxInternal2/SharedFoldersEnableSymlinksCreate/<shared-fs-name> 1

at the host. Where, <client-name> is the vbox client name, and <shared-fs-name> is the shared folder(or filesystem) name between host and client.

See https://www.virtualbox.org/ticket/15945

0

For me the issue was that yarn.lock file was set to readonly by Perforce, as I pulled it from a Perforce repository.

0

If you are trying to install a package, include the force flag --force.

If faced the above error while trying to install the heroicons package.

$ npm install @heroicons/react --force

By including the force flag npm was able to force the installation.

Note: Before attempting installation, stop the development server.

Hope you find this helpful.

0

I had the same issue, which was solved with this Python script

import os

# Find all Node.js processes
pids = os.popen('tasklist /v /fi "imagename eq node.exe" /fo csv').read().strip().split('\n')[1:]
pids = [int(pid.split(',')[1].replace('"', '')) for pid in pids]

# Kill all Node.js processes
for pid in pids:
    os.system(f'taskkill /pid {pid} /f')

Now the error [Error: EPERM: operation not permitted is gone

0

I had this exact bug happening. I had to stop Visual Studio Code, then I re-ran the command and it just worked.

Seems like the dev server in Visual Studio was locking a file.

0

if non of the above worked for you try this

  1. yarn cache clean

  2. check you'r node version try changing to latest

  3. rm -rf node_module then yarn install

  4. yarn self-update

Not the answer you're looking for? Browse other questions tagged or ask your own question.