Last updated: Apr 4, 2024
Reading timeยท2 min
To solve the error "npm ERR! Error: EPERM: operation not permitted":
node_modules
and package-lock.json
.npm install
command.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:
Open your terminal in your project's root directory and run the following commands.
# ๐๏ธ 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
If you get a permissions error on Windows, open CMD as an administrator and rerun the command.
To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
npm install -g npm@latest npm install -g npm@latest --force
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.
npm install --force
If you can't get npm
to work, try using yarn
instead.
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.