简体   繁体   中英

npm command - Error: EISDIR: illegal operation on a directory, read

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?

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:

  • per-project
  • per-user
  • global
  • built-in

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

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.

我遇到了同样的问题,但在删除“C:/Users/{username}/”目录中的 .npmrc 文件后它得到了修复。

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 😇

Try to uninstall the yarn and run the npm install command again. If works, install the yarn new version.

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本地主机返回错误:EISDIR:对目录的非法操作,读取

And that happens because you may have named /user.js/index.js

原因是带有 .js 扩展名的文件夹名称拼写错误

So to fix this, you just have to rename your folder name as user. This is just an example but can really happen.

查找并删除.npmrc文件夹,通常位于C:/Users/<username>/.npmrc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM