Reputation: 15647
While issuing the npm
command I'm receciving an error stating,
Error: EISDIR: illegal operation on a directory, read
TypeError: Cannot read property 'get' of undefined
SO Posts which I have gone through in this regard (which didn't resolve my issue):
Using Node.js I get, "Error: EISDIR, read"
Node.JS readFileSync() function
I have also tried editing the .npmrc
file to remove the ca
entry and even after that the issue still persists.
Can someone help?
Upvotes: 7
Views: 37317
Reputation: 104
Aside from the other answers, there could be possibility that it will return an error of Error: EISDIR because you may have named a supposedly a folder path, with an extension.
For example, you have folder that is called user and inside that folder is index.js, but instead, you have misspelled the user folder to user.js.
This can happen in Next.js's folder structure for dynamic rendering inside the /pages folder. Inside that folder, for instance, you wanted to create a route for user. That would be http://localhost:3000/user. While you think you have this folder structure /pages/user/index.js, instead you have mistakenly named user folder as user.js, so the folder path became /pages/user.js/index.js. This will in fact will return
And that happens because you may have named /user.js/index.js
So to fix this, you just have to rename your folder name as user. This is just an example but can really happen.
Upvotes: 3
Reputation: 1682
Try to uninstall the yarn and run the npm install command again. If works, install the yarn new version.
Upvotes: 0
Reputation: 896
From personal experience, based on your error message illegal operation on a directory
, I would guess that while executing npm, it is unable to access a directory or file.
As others have mentioned, this is typically an error related to your .npmrc file (typically located in a user's home directory, ~/.npmrc) which stores custom configurations for npm. It is important to note that npm can have configurations at various levels:
You can read about the different locations an .npmrc might exist, as well as other documentation pertaining to npm config files on the npmrc documentation page.
If you'd prefer to investigate the source of the issue rather than just removing your .npmrc file you can do so by opening .npmrc in a text editor (VS Code, notepad, etc), or by issuing the command:
npm config edit
When .npmrc is opened in your text editor, you can begin reviewing any configurations you have. If the file is empty or doesn't exist then you don't have any configurations (at that level) and you can move on to investigating .npmrc configurations at another level or other sources of the issue.
Similarly if your .npmrc file only contains lines of text that start with a semicolon (;) then you have no active configurations, as a semicolon acts as a commented (inactive) line in the .npmrc. In certain cases, like if you ever ran npm config list
then npm has created a sample .npmrc file for you with an list of possible settings to configure, but all these settings are inactive as they are preceded by a semicolon. Below is a snippet of the file generated by npm when npm config list
is run:
;;;;
; npm userconfig file
; this is a simple ini-formatted file
; lines that start with semi-colons are comments.
; read `npm help config` for help on the various options
;;;;
; all options with default values
;;;;
; access=null
; allow-same-version=false
Once you've verified that you have custom configurations active in .npmrc, then a likely cause of this error might be any custom configurations you have that reference a file location on your machine. In my case I was referencing an incomplete path to my ca certificate for the cacert property in .npmrc:
Broken Configuration:
; settings located in ~/.npmrc
cafile=C:/Users/kfrisbie/Documents/certs
Note that above "certs" was a reference to a directory, where npm was expecting a reference to a file, so when I updated the path to reference the file I intended within the directory, npm began functioning without error again.
Fixed Configuration:
; settings located in ~/.npmrc
; note, I was missing the name of the file in the certs directory
cafile=C:/Users/kfrisbie/Documents/certs/trusted_certs.pem
Upvotes: 4
Reputation: 1427
For me (an idiot), the problem was that package-lock.json
was somehow a directory containing my package-lock.json
file...
Deleting the directory and placing the file where it belongs (at the root of my project) fixed this issue.
Hope this helps anyone so i don't feel so bad about myself 😇
Upvotes: 2
Reputation: 9
Find and remove the .npmrc
folder, usually located at C:/Users/<username>/.npmrc
Upvotes: -1
Reputation: 31
I had the same issue but it got fixed after deleting .npmrc file in "C:/Users/{username}/" directory.
Upvotes: 2
Reputation: 91
I had the same issue but after lot of research i was able to fix it.
First try to locate you npmrc file in your computer. Try this command to locate .npmrc
file.
npm config ls -l | grep config
Usually .npmrc
locates in /Users/USER_NAME
. After that run rm .npmrc
. It will delete node user config but you should be fine. Hope this helps you.
Upvotes: 2