244

I am stuck with this error no matter what directory I am in, and what I type after "npm" in cmd.exe. Here is the npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js' ]
2 info using npm@2.14.12
3 info using node@v4.2.6
4 verbose stack Error: EISDIR: illegal operation on a directory, read
4 verbose stack     at Error (native)
5 verbose cwd C:\Users\me
6 error Windows_NT 6.1.7601
7 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
8 error node v4.2.6
9 error npm  v2.14.12
10 error code EISDIR
11 error errno -4068
12 error syscall read
13 error eisdir EISDIR: illegal operation on a directory, read
13 error eisdir This is most likely not a problem with npm itself
13 error eisdir and is related to npm not being able to find a package.json in
13 error eisdir a package you are trying to install.
14 verbose exit [ -4068, true ]

I have tried and uninstalling/reinstalling nodejs multiple times, I even deleted npm and npm-cache folders in C:\Users\me\AppData\Roaming. I'm not sure what went wrong to cause this. One second it was working fine, and now I can't get rid of this error. The explanation in the log does not make sense, as it gives this error in any directory. I should note that running a command prompt as administrator does not give this error. I'm pulling my hair out this Friday evening trying to get this fixed, any help would be greatly appreciated!

AnotherMike
  • 2,633
  • 2
  • 16
  • 15
  • 1
    I'm finding this error is common when people update npm, I'm wondering if this error started when you updated npm, or if you even updated at all? – Clavin Jan 23 '16 at 03:19
  • It's a new computer so I had installed node in the last few days. I just did an update in adminstrator mode, but not luck – AnotherMike Jan 25 '16 at 18:24
  • I've spent the past 3 hours on this, I finally figured it out -- turns out I accidentally ran "mkdir .gitignore" – Lumin Dec 22 '20 at 17:58

41 Answers41

470

EISDIR stands for "Error, Is Directory". This means that NPM is trying to do something to a file but it is a directory. In your case, NPM is trying to "read" a file which is a directory (Line: 4). Since the operation cannot be done the error is thrown.

Three things to make sure here.

  1. Make sure the file exists. If it does not, you need to create it. (If NPM depends on any specific information in the file, you will need to have that information there).
  2. Make sure it is in fact a file and not a directory.
  3. It has the right permissions. You can change the file to have all permissions with "sudo chmod 777 FILE_NAME". (Careful: You are giving Read, Write and Execute permissions to every one on that file)
MauricioLeal
  • 6,221
  • 2
  • 21
  • 28
  • 26
    This should be the accepted answer imo as it contains info about the problem as well as a solution – schu34 Dec 22 '17 at 15:22
  • 4
    How idiot am I? I was in a subfolder ahahahah thanks. – Sampgun May 02 '18 at 12:54
  • 8
    Spent 3 hours on this. I had a folder called back-button.css. 3 hours I'm never getting back. Thanks to you it wasn't 4. – Loke Nov 18 '18 at 10:20
  • 2
    I got this using fs.writeFile - but an error stopped my program from passing the FileName so it was trying to write on a folder. Thanks. – Michael Nelles Dec 12 '18 at 07:40
  • 1
    That's correct. I faced this issue while using **nodemailer** in an **NW.js** desktop app while writing code for an email manager. I was also trying to read directory instead of reading an image file to send as an attachment. Thank you very much. – hygull Dec 21 '18 at 12:19
  • Looking for clarification, I found the problem directory, but after I "Make sure it is in fact a file and not a directory" am I then deleting the directory, or replacing it with a file of some sort? – Kevin H. Feb 09 '19 at 01:55
  • 1
    @KevinHyde It would really depend on why Node tried that operation on that particular directory. Was that directory specified in a path ("./directory" but you need "./directory/theFileYouNeed")? Was that directory created by npm or was it created by you? A common mistake is to create a directory with a certain name but the intention was to create a file. If that does not help please feel free to contact me directly. – MauricioLeal Feb 18 '19 at 21:17
  • For me, while using `fs.copyFileSync`, destination was a directory. I was not aware, that should be a file. – Omid May 30 '19 at 15:03
  • 1
    I'm stuck here as the log doesn't state a path, same as OP here, or am I blind? – Giszmo Dec 20 '19 at 01:23
  • 1
    If only the error message would display the attempted filename as well – bvgheluwe Mar 17 '21 at 13:17
  • SImilar issue to @MichaelNelles here, instead of writeFile I used `fs.readFile(stupidfolder)` and got the error with a dir as parameter. – Timo Aug 23 '22 at 07:29
  • node was trying to read a directory as a file, issue resolved. Thanks – Leon Matota Nov 17 '22 at 09:41
82

I ran into the same problem while I was changing some npm settings. I did a mistake with one npm config set command and this added a line referring to a non-existing directory to C:\Users\{User}\.npmrc. After I deleted that line manually from .npmrc, the problem was gone.

user1460043
  • 2,331
  • 1
  • 19
  • 26
  • 5
    How idiot am I? I was in a subfolder ahahahah thanks. – Sampgun May 02 '18 at 12:55
  • Me too, I was pointing cafile to a folder instead of an actual file, and every `npm` command stopped working completely, no solution worked apart from your answer, thanks! – Giorgio Tempesta Sep 17 '18 at 14:02
  • For those coming from **linux**: `.npmrc` is in one of the paths described here: https://docs.npmjs.com/cli/v7/configuring-npm/npmrc – Emran May 06 '21 at 09:39
  • For me the issue was very basic instead of creating `.env` file i created a folder with same name, therefore i was getting **EISDIR**. – Lokesh Singal May 14 '21 at 12:12
  • In my case, I went to that path, everything is available. Actually I'm getting this error when I try to debug the project, otherwise without debugging my project is working fine. – Harsha May 27 '21 at 11:16
14

In my case I was getting the "EISDIR: illegal operation on a directory, read" because in my .angular-cli.json file I wasn't providing a full path in "scripts:"

For example I had

"scripts": [
        "../node_modules/hammerjs",
        "../node_modules/moment"
      ],

In fact it should have been

"scripts": [
        "../node_modules/hammerjs/hammer.min.js",
        "../node_modules/moment/min/moment.min.js"
      ],
Rob
  • 419
  • 5
  • 9
14

Had the same problem today after i've upgraded my npm from version 6.4.1 to version 6.5.0. I fixed this by downloading the .pkg installer (recommended for most users) from node.js and runned it afterwards.

PeeJee
  • 536
  • 6
  • 22
8

I had the same issue on Mac OS X (installed with homebrew), and the .npmrc is not the only place node stored config variables. There is a glocal npmrc config file in /usr/local/etc that you have to edit using this command:

sudo nano npmrc

Remove the ca= line, or whatever the config setting was that broke your install, save that file, and try npm again, and you should see it working.

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Ryan
  • 3,153
  • 2
  • 23
  • 35
8

These strange errors occured recently on my OSX machine.

I could help myself the quick & dirty way by running:

sudo chmod -R 777 /usr/local/lib/node_modules/

Something seemed to have messed up the access rights of all global node modules.

dy_
  • 2,433
  • 24
  • 27
8

For me it was because I was using the the wrong path; it should have been a path to a file yet I was wrongly using a path to a directory:

Changed this:

path.resolve(__dirname, '../');

Into this:

path.resolve(__dirname, '../.env')
Omar Dulaimi
  • 846
  • 10
  • 30
5

So most of the answers were saying it was related to the .npmrc file.

In my case, I was deploying a serverless application using serverless deploy and the message

EISDIR: illegal operation on a directory, unlink '/home/malvadao/workspace/project/.build/node_modules'

was being thrown.

Deleting the .build folder did it for me. It was the folder generated after Typescript compilation. Since the folder is recreated after launching the serverless deploy command, it was enough to solve the problem and continue the flow.

In other words, manually deleting the folder might be enough for you to move forward, without the need to touch .npmrc

malvadao
  • 3,362
  • 1
  • 20
  • 22
3

If your problem is associated with the React Native packager. Try resetting the cache with react-native start --reset-cache.

Friendly-Robot
  • 1,124
  • 14
  • 24
3

For me fixing was add slash after directory name

Miniwe
  • 31
  • 2
3

Make sure node_modules (and your root package.json) doesn't contain a reference to npm's "package.json" module. Deleting package.json FOLDER from node_modules solved the issue for me.

Benjamin Piette
  • 3,645
  • 1
  • 27
  • 24
3

Just delete .npmrc folder in c:users>'username' and try running the command it will be resolved !

2

Doing a complete uninstall, including removing paths, etc and reinstalling has solved the problem, very strange problem though.

How to completely remove node.js from Windows

AnotherMike
  • 2,633
  • 2
  • 16
  • 15
  • In first place I did not like your answer, but I have to confess that the same thing happed to me. Creating a new `meteor` project with `--react` caused this issue, but deleting the project and recreating it again worked (OS X). – Hola Soy Edu Feliz Navidad Sep 07 '19 at 13:31
2

I had this issue with gulp. The problem was that gulp added a dependency to my source file and I think npm tried to open it:

{
  "name": "name",
  "version": "2.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "appname": "file://gulp",
    "gulp-concat": "^2.6.1",
    "gulp-electron": "^0.1.3",
    "gulp-shell": "^0.5.2",
    "gulp-uglify": "^2.0.0",
    "gulp-util": "^3.0.7",
    "node-7z": "^0.4.0"
  }
}

Make sure that there are no strange references in you package.json file.

Lanklaas
  • 2,870
  • 1
  • 15
  • 18
2

Check to ensure you are running npm install from the proper directory.

(The package.json file could be one extra directory down, for example.)

James Lawruk
  • 30,112
  • 19
  • 130
  • 137
2

Had the same problem until I tried deleting the .git folder. It worked. I guess this type of problem can have different causes.

2

In my case I forgot to pass the full path of one of the file it was asking. After passing full path of the file worked :)

Rafael Paz
  • 497
  • 7
  • 22
1

In my case, i was facing this issue while installing create-react-app in MAC (Mojave OS) with following command :

sudo npm install create-react-app -g

and got errors like this :

npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/scheduler'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/symbol'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/testing'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/util'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/webSocket'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/symbol'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/testing'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/util'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/webSocket'

I have read npm.community that try to install without sudo :

npm install create-react-app -g

and it actually solved my issue ..!!

Ritesh
  • 4,720
  • 6
  • 27
  • 41
1

I had the same problem.

Recently just deleted the .npmrc file in the user directory and afterwards, I ran npm init -y

Works!

Daniel
  • 19
  • 1
1

In my case, my fault was assuming, that script allow to work with directories, but it waited FILE PATH, so try to set full path to file.

In my case was:

['/var/task/myFolder']

but right path should be :

['/var/task/myFolder/sample.tgs']

Project related to chromium usage inside puppeteer on serverless was lambda. Hope, it helps.

Nigrimmist
  • 10,289
  • 4
  • 52
  • 53
0

I had a similar problem while setting up boilerplate code. It was reading my bundle.js file as a directory. So as stated here. EISDIR mean its a directory and not a file. To fix the issue, I deleted the file and just recreated (it was originally created automatically). If you cannot find the file (because its hidden), simply use the terminal to find and delete it.

0

I had the same issue. There was a linked folder in my directory which was causing the issue. i added that folder to ignore list and then it started working fine as expected.

ujjaldey
  • 421
  • 2
  • 5
  • 17
0

I know this isn't specifically asking about forever js.. but google lead me here so.. For me it was as simple as an ending slash.

I just changed:

forever start -a -l /dev/null/ /var/www/node/my_file.js

To:

forever start -a -l /dev/null /var/www/node/my_file.js

And the error disappeared

Marc Alexander
  • 761
  • 11
  • 24
0

Make sure to check your version of npm and whether or not there are issues with it. I was having the same issue at the time of this post and I discovered that my npm version (6.5) was having issues. I had to uninstall and reinstall npm version 6.4.1 and then everything started to work great again.

smoosh911
  • 516
  • 7
  • 8
0

I had a broken symlink to node_modules in a subfolder

Daniel Kukula
  • 333
  • 3
  • 7
0

In my case, I'm using Windows 10 in Spanish and this version mixes English and Spanish directory names. My problem was that the desktop directory has this name for some commands and escritorio to others. I believe that npm cannot resolve this. My solution was to simply change to another directory starting from C:\ different to my home directory.

Worthwelle
  • 1,244
  • 1
  • 16
  • 19
JJEA
  • 1
0

I had faced similar issue. I set cafile using the command:

npm config set cafile PATH_TO_CERTIFICATE

I was able to resolve this by deleting the certificate file settings, and setting strict-ssl = false.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
0

I fixed this issue by moving my directory from my exFAT drive which does not support symlinking.

My exFat drive is shared between osx and a bootcamp windows partition so when I tried to clone and npm install my project it was failing but never explains that exFAT doesn't support this functionality.

There are drivers out there that you can install to add the ability to symlink but you'll have to do a lot of your setup manually compared to running a simple npm script.

Matt
  • 542
  • 5
  • 6
0

For mac os: If installed directly from nodejs website the npmrc file would be located in /usr/local/etc/npmrc. Just delete the config which is undefined and this problem would be fixed.

Rajat Gupta
  • 91
  • 1
  • 1
  • 2
0

In my case, the C:\Users\{user}\AppData\local\npm files were hidden, so I was not able to find & delete the trouble directory. Took me DAYS to realize this!

So double check to un-hide any folders so you don't miss them! Here's a link to do this if you don't know how.

notnoahkirby
  • 309
  • 6
  • 17
0

In my case issue was that space character was in the name of the source folder (Windows 10).

Embedded
  • 33
  • 6
0

In my case, I am working on angularv10 with material. I had changed some script files and forgot to remove these empty "" in the scripts array

scripts: [.....bla, bla, etc, ""]

remove these empty""

npm clear-cache --force

close and open vscode

It worked.

vivek
  • 541
  • 5
  • 8
0

This happened to me on npm publish --access public command. Project contained directory named package.json. This error is sad - because project HAS to have this directory and named exactly package.json (it was part of test case fixture to assert correct behavior of this lib).

animaacija
  • 170
  • 9
  • 25
0

I came across this problem today while working in Visual Studio Code. I was able to resolve the issue by correcting the prettier config path set in my user settings. To verify your path settings, select File > Preferences > Settings. Within your user settings, search for Path to the prettier configuration file and make sure it's correct.

  • Although path pointed to a non-existent `.prettierrc.yaml` s/b `.prettierrc.js` in my case, that didn't fix my issue. Thanks for the tip, though. – Mike S. Apr 18 '22 at 18:06
0

I'm using Mix v6.0.29 from Laravel v8.56.0

In webpack.mix.js, when copying directories using

mix.copyDirectory("resources/js", "public/js");

Check for inner folders, it should not contain dot/s (.) otherwise, this error would pop up.

I think for this specific version, paths (or folders) with dot/s followed by some characters, would resemble a file extension, then will be treated as a "file" regardless if it's a "folder".

claw68
  • 374
  • 3
  • 10
0

After my mac upgrade. I started having this issue. I tried reinstalling nvm, node, npm, clearing npm cache, reinstalling the dependencies of the project after deleting the node_modules folder, resetting npmrc ...

The only thing that worked was cloning the project again and it worked from the same branch and same commit.

Melchia
  • 22,578
  • 22
  • 103
  • 117
0

In my case, "Error: EISDIR: illegal operation on a directory, read" the problem was in the name of the folder I was in. It seems, using special characters, in my case #, on a windows system also results in this error.

0

For me it was not project specific, I was getting EISDIR error even with following command

yarn --help

to fix this issue, I tried to find out which file yarn cli is trying to read but is a Directory

I ran following command outside of my reactjs project directory and was able to find out where this error was thrown. enter image description here

as per screen shot I opened cli.js file and added following line of code in line number 88615, this will help display the file path that is causing this issue

console.log(possibleLoc)

Then I ran yarn --help again, this time I can see which file path, yarn is considering as file but is a directory enter image description here

I renamed the file and this fixed the issue

pavels
  • 41
  • 3
-1

In my case these steps solved my problem:

  1. terminating npm process (CTRL + C)
  2. deleting entire folder
  3. creating new one
  4. running npm again
BartusZak
  • 1,041
  • 14
  • 21
-2

On Mac:

Per-user config file: ~/.npmrc

Michael D. Irizarry
  • 6,186
  • 5
  • 30
  • 35
-3

I just removed the line

.babel('resources/assets/js/app.js')

for laravel 5.6 with vue.js. in webpack.mix.js