npm ERR! Error: EPERM: operation not permitted [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
2 min

banner

# npm ERR! Error: EPERM: operation not permitted [Solved]

To solve the error "npm ERR! Error: EPERM: operation not permitted":

  1. Close your IDE (e.g. Visual Studio Code) and stop your development server.
  2. Clean the cache and delete node_modules and package-lock.json.
  3. Rerun the npm install command.

npm err error eperm

shell
npm ERR! path C:\Users\bobbyhadz\Desktop\my_project npm ERR! code EPERM npm ERR! errno -4048 npm ERR! syscall lstat npm ERR! Error: EPERM: operation not permitted, lstat 'C:\Users\bobbyhadz\Desktop\my_project' npm ERR! at Error (native) npm ERR! Error: EPERM: operation not permitted, rename C:\Users\bobbyhadz\Desktop\my_project

The first thing you should try is to:

  • Stop your development server if it's running.
  • Close your IDE (e.g. Visual Studio Code) if you have your project open.
  • If you have your project open in Explorer, close the windows.

Open your terminal in your project's root directory and run the following commands.

shell
# ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ update your npm version npm install -g npm@latest --force # ๐Ÿ‘‡๏ธ clean npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install

clean npm cache with force flag

If you get a permissions error on Windows, open CMD as an administrator and rerun the command.

To open CMD as an administrator:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Rerun the command.
shell
npm install -g npm@latest npm install -g npm@latest --force

install npm latest version

Another thing you can try is to run the npm install command with the --force option.

Make sure your terminal is opened in the root directory of your project (where your package.json) file is.

shell
npm install --force

npm install with force flag

If you can't get npm to work, try using yarn instead.

The error most often occurs because of permissions issues, e.g. because your node_modules directory or package-lock.json file have been set to read-only.

You can try to open CMD as an administrator (Windows) or prefix your npm command with sudo (macOS or Linux) if you haven't.

If you created your project in a directory you have no permission to write to, e.g. C:\my_project, you can try creating your project in a different directory or drive, e.g. D:\projects\my_project.

If your IDE (e.g. Visual Studio Code) or dev server is running in the background, it might be blocking the npm command you are trying to issue.

Try closing your IDE and development server before issuing the command.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev