node.js 包的 NPM 安装不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26307910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:59:19  来源:igfitidea点击:

NPM install for packages not working

node.jsterminalnpmbowerbower-install

提问by user2793755

T hanks in advance for any help I can get.

提前感谢我能得到的任何帮助。

I am trying to install packages like grunt, bower, and yeoman using nodejs and the NPM in my mac OSX 10.8's terminal.

我正在尝试在 Mac OSX 10.8 的终端中使用 nodejs 和 NPM 安装 grunt、bower 和 yeoman 等软件包。

I check node and NPM's versions to confirm they are installed correctly and have found that to be true. However when I begin to run a command to install a package like bower, using the following:

我检查了 node 和 NPM 的版本以确认它们安装正确,并发现这是真的。但是,当我开始运行命令来安装像 bower 这样的软件包时,请使用以下命令:

npm install -g bower

I get various amounts of errors coming up. I am trying to avoid using the sudo command. I tried using sudo, but afterwards I would get a response "command not found." I have a feeling the packages may not be in the correct folders or directories but I am unclear on what to do next.

我收到了各种各样的错误。我试图避免使用 sudo 命令。我尝试使用 sudo,但之后我会收到“找不到命令”的响应。我有一种感觉,这些包可能不在正确的文件夹或目录中,但我不清楚接下来要做什么。

For your reference these are the errors I get:

供您参考,这些是我得到的错误:

npm ERR! Error: EACCES, unlink '/Users/myname/.node/lib/node_modules/bower/.editorconfig'
npm ERR!  { [Error: EACCES, unlink '/Users/myname/.node/lib/node_modules/bower/.editorconfig']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/myname/.node/lib/node_modules/bower/.editorconfig' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.5.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/myname
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! path /Users/myname/.node/lib/node_modules/bower/.editorconfig
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/Users/myname/.node/lib/node_modules/bower/.editorconfig'
npm ERR! error rolling back Error: EACCES, unlink '/Users/myname/.node/lib/node_modules/bower   /.editorconfig'
npm ERR! error rolling back  { [Error: EACCES, unlink '/Users/myname/.node/lib/node_modules/bower/.editorconfig']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/Users/myname/.node/lib/node_modules/bower/.editorconfig' }
npm ERR! not ok code 0

For privacy, I replaced my own name with the proxy myname in the paths. Moreover, this problem persists when I try installing grunt, and yeoman.

为了隐私,我用路径中的代理 myname 替换了我自己的名字。此外,当我尝试安装 grunt 和 yeoman 时,这个问题仍然存在。

Upon further inspection, I noticed I have two folders. One named 'users' and one name 'usr.' Within 'users', I see a folder called node_modules. However, within 'usr/local/lib/node_modules/npm/node_modules' I noticed there is no bower, grunt, or yeoman files. This is just speculation, but are the files not properly installing into the necessary folders for them to be run in npm?

经过进一步检查,我注意到我有两个文件夹。一个名为“users”,一个名为“usr”。在“用户”中,我看到一个名为 node_modules 的文件夹。但是,在“usr/local/lib/node_modules/npm/node_modules”中,我注意到没有 bower、grunt 或 yeoman 文件。这只是猜测,但是这些文件是否没有正确安装到必要的文件夹中以便它们在 npm 中运行?

Any help or input would be extremely appreciated!

任何帮助或输入将不胜感激!

UPDATE10/10/14

更新10/10/14

For people's reference, I have tried the sudo command to see if it would work, and it displays the following:

供大家参考,我试过 sudo 命令看看它是否有效,它显示以下内容:

   /Users/myname/.node/bin/bower -> /Users/myname/.node/lib/node_modules/bower/bin/bower
     [email protected] /Users/myname/.node/lib/node_modules/bower
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected], [email protected], [email protected])
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], [email protected])
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], strip- [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
    ├── [email protected]
    ├── [email protected] ([email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
    ├── [email protected] ([email protected], [email protected])
    └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

================================ However, the above is not a proper solution. When I try running a check to see if bower is installed like by typing bower -v or bower --version or any other bower command, I get "command not found." What is going on?

============================== 然而,以上并不是一个正确的解决方案。当我尝试通过键入 bower -v 或 bower --version 或任何其他 bower 命令运行检查以查看是否安装了 bower 时,我得到“找不到命令”。到底是怎么回事?

UPDATE 10/11/14

更新 10/11/14

So nothing I have tried so far has given me the ability to run the command 'npm install -g bower.' Out of curiosity, as I have mentioned before, I have ran the 'sudo npm install -g bower command' which appeared to install bower. However, typing any bower commands still yields 'command not found.' Upon trying sudo bower commands leads to 'command not found' as well. What I do not understand though is that when I run the command 'npm ls' to look at what the NPM has installed, I interestingly have a list of the following installed packages. You do not need to read the list as it is long, but take note of how the first item appears to be bower. If this is true, and it means that bower was in fact installed by npm, why therefore, are bower commands not working?

所以到目前为止我没有尝试过任何让我能够运行命令“npm install -g bower”的能力。出于好奇,正如我之前提到的,我运行了似乎安装 bower 的“sudo npm install -g bower 命令”。但是,输入任何 bower 命令仍然会产生“未找到命令”。尝试 sudo bower 命令后也会导致“找不到命令”。但我不明白的是,当我运行命令“npm ls”来查看 NPM 已安装的内容时,有趣的是我有一个以下已安装软件包的列表。您不需要阅读该列表,因为它很长,但请注意第一项看起来如何是 bower。如果这是真的,并且这意味着 bower 实际上是由 npm 安装的,那么为什么 bower 命令不起作用?

    /Users/myname.
    ├─┬ [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ └─┬ [email protected]
    │ │ │ │   └── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ └─┬ [email protected]
    │ │   └── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   └── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ └─┬ [email protected]
    │ │   └── [email protected]
    │ ├─┬ [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ └─┬ [email protected]
    │ │   └── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ └─┬ [email protected]
    │ │   └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ └─┬ [email protected]
    │ │   ├── [email protected]
    │ │   └─┬ [email protected]
    │ │     └── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├─┬ [email protected]
    │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ └── [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   └── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   ├── [email protected]
    │ │ │   ├── [email protected]
    │ │ │   └── [email protected]
    │ │ ├── [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├─┬ [email protected]
    │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ └── [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├── [email protected]
    │ │ │ │ ├─┬ [email protected]
    │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ └── [email protected]
    │ │ │ │ ├─┬ [email protected]
    │ │ │ │ │ ├─┬ [email protected]
    │ │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ │ └── [email protected]
    │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ └── [email protected]
    │ │ │ │ └─┬ [email protected]
    │ │ │ │   └── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ └─┬ [email protected]
    │ │ │ │   ├── [email protected]
    │ │ │ │   ├── [email protected]
    │ │ │ │   └── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   └── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ └─┬ [email protected]
    │ │   └── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ └─┬ [email protected]
    │ │   └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   ├── [email protected]
    │ │ │   ├── [email protected]
    │ │ │   ├── [email protected]
    │ │ │   └── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └── [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ ├── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ └─┬ [email protected]
    │ │ │ │   └── [email protected]
    │ │ │ └── [email protected]
    │ │ └─┬ [email protected]
    │ │   ├── [email protected]
    │ │   ├─┬ [email protected]
    │ │   │ └─┬ [email protected]
    │ │   │   └── [email protected]
    │ │   ├─┬ [email protected]
    │ │   │ ├── [email protected]
    │ │   │ ├── [email protected]
    │ │   │ ├── [email protected]
    │ │   │ └── [email protected]
    │ │   └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├─┬ [email protected]
    │ │ │ │ ├─┬ [email protected]
    │ │ │ │ │ ├── [email protected]
    │ │ │ │ │ └── [email protected]
    │ │ │ │ └── [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   ├─┬ [email protected]
    │ │ │   │ └── [email protected]
    │ │ │   └─┬ [email protected]
    │ │ │     └─┬ [email protected]
    │ │ │       ├─┬ [email protected]
    │ │ │       │ └── [email protected]
    │ │ │       ├── [email protected]
    │ │ │       ├── [email protected]
    │ │ │       ├─┬ [email protected]
    │ │ │       │ └── [email protected]
    │ │ │       └── [email protected]
    │ │ ├── [email protected]
    │ │ └─┬ [email protected]
    │ │   └─┬ [email protected]
    │ │     └── [email protected]
    │ └── [email protected]
    ├─┬ [email protected]
    │ └── [email protected]
    ├─┬ [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └─┬ [email protected]
    │ │ │   ├── [email protected]
    │ │ │   └── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├─┬ [email protected]
    │ │ │ ├── [email protected]
    │ │ │ └── [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├─┬ [email protected]
    │ │ ├── [email protected]
    │ │ └── [email protected]
    │ ├─┬ [email protected]
    │ │ └── [email protected]
    │ ├── [email protected]
    │ ├── [email protected]
    │ └── [email protected]
    └─┬ [email protected]
      ├─┬ [email protected]
      │ ├── [email protected]
      │ ├── [email protected]
      │ ├─┬ [email protected]
      │ │ ├── [email protected]
      │ │ └── [email protected]
      │ └── [email protected]
      └─┬ [email protected]
        ├─┬ [email protected]
        │ ├── [email protected]
        │ └── [email protected]
        ├─┬ [email protected]
        │ ├── [email protected]
        │ └─┬ [email protected]
        │   ├── [email protected]
        │   └── [email protected]
        ├── [email protected]
        └─┬ [email protected]
          ├─┬ [email protected]
          │ ├── [email protected]
          │ ├── [email protected]
          │ ├── [email protected]
          │ └── [email protected]
          └─┬ [email protected]
            └── [email protected]

回答by Per Quested Aronsson

This solved the problem for me:

这为我解决了问题:

sudo chown -R `whoami` ~/.node/lib/node_modules/bower/
npm install -g bower
bower -v
1.3.12

You shouldn't have to run npm install as sudo.

您不必以 sudo 的身份运行 npm install。

回答by user3731073

This worked for me:

这对我有用:

I basically gave my user permissions to the directory mentioned right after this -> stack Error: EACCES, unlink..., in your case it would be something like sudo chown -R USERNAME /Users/myname/.

我基本上给了我的用户权限在此之后提到的目录 -> stack Error: EACCES, unlink...,在您的情况下,它类似于sudo chown -R USERNAME /Users/myname/.

For people who are new to this, don't forget to change USERNAME in the command above with your own, if you don't know your username, simply run whoamito get it.

对于刚接触这个的人,不要忘记用你自己的改变上面命令中的 USERNAME,如果你不知道你的用户名,只需运行whoami即可获取它。

After that you can install any package withoutthe need to use sudo, npm install -g SomePackage.

之后,你可以安装任何包,而不需要使用sudo, npm install -g SomePackage

回答by VtoCorleone

Run the global (-g) installs as admin.

以管理员身份运行全局 (-g) 安装。

> sudo npm install -g bower

You got this error -

你有这个错误 -

npm ERR! Please try running this command again as root/Administrator.

***** UPDATE BELOW *****

***** 下面更新 *****

Check if it is installed and get the version

检查是否安装并获取版本

> bower -v

You might not be able to see bower now because it installed as admin. Try getting the version number by running

您现在可能看不到 bower,因为它以管理员身份安装。尝试通过运行获取版本号

> sudo bower -v

You should see the version number now.

您现在应该会看到版本号。

Take ownership of the package with chown

使用 chown 获取包的所有权

> cd /Users/<username>/.npm
> chown <username> bower*

I personally take ownership of everything in the /Users/ directory. It is your directory and not global.

我个人拥有 /Users/ 目录中的所有内容。它是您的目录而不是全局目录。

> chown <username> *

***** UPDATE 2 BELOW *****

***** 下面更新 2 *****

It looks like it's a PATH problem now. Do you see the npm directory in the PATH when you type

现在看起来这是一个 PATH 问题。输入的时候有没有在PATH中看到npm目录

> echo $PATH

I use MacPorts so npm and node install in the /opt/local/bin and /opt/local/sbin directories. I did a quick check on the net and it looks like you need to have the following /usr/local/bin if you installed the package from the node site.

我使用 MacPorts,因此 npm 和 node 安装在 /opt/local/bin 和 /opt/local/sbin 目录中。我在网上进行了快速检查,如果您从节点站点安装了软件包,则看起来您需要以下 /usr/local/bin。

Check out this article about installing node (particularly the part about the PATH.

查看这篇关于安装节点的文章(特别是关于 PATH 的部分。

That link also references this article on how to modify your PATH.

该链接还引用了有关如何修改 PATH 的这篇文章。

Hope that helps.

希望有帮助。

回答by Jonathan Garner

I was having similar issues when trying to install bower through NPM.

我在尝试通过 NPM 安装 bower 时遇到了类似的问题。

I am not an expert on this but was sure it was connected to $PATH and found 2 articles which in combination fixed this for me perfectly.

我不是这方面的专家,但确定它已连接到 $PATH 并找到了 2 篇文章,这些文章结合起来完美地为我解决了这个问题。

The first is this gist by Dan Haerbert: https://gist.github.com/DanHerbert/9520689

第一个是 Dan Haerbert 的这个要点:https://gist.github.com/DanHerbert/9520689

Dan says

丹 说

"If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do npm update npm -g, you will see an error like this:"

“如果你是一个 Mac Homebrew 用户并且你通过 Homebrew 安装了 node,那么 Homebrew 和 NPM 一起工作的方式存在一个重大的哲学问题。如果你用 Homebrew 安装 node 然后尝试执行 npm update npm -g,你会看到这样的错误:”

The error he shows is very similar to your original error.

他显示的错误与您的原始错误非常相似。

His solution is to re-install node but to make sure that NPM is not installed via homebrew since, as he says:

他的解决方案是重新安装节点,但要确保 NPM 不是通过自制软件安装的,正如他所说:

npm is its own package manager and it is therefore better to have npm manage itself and its packages instead of letting Homebrew do it. Also, using the Homebrew version of npm requires sudo to install global packages. That's also a very bad idea.

npm 是它自己的包管理器,因此最好让 npm 管理它自己和它的包,而不是让 Homebrew 来管理它。此外,使用 npm 的 Homebrew 版本需要 sudo 来安装全局包。这也是一个非常糟糕的主意。

He says to uninstall node and then re-install it with the following commands:

他说要卸载节点,然后使用以下命令重新安装它:

brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
curl -L https://www.npmjs.org/install.sh | sh

And then to finish up with

然后结束

export PATH="$HOME/.node/bin:$PATH"

This worked for me and fixed all my issues. I was able to run 'npm install -g bower' without getting the error message.

这对我有用并解决了我的所有问题。我能够运行“npm install -g bower”而没有收到错误消息。

Finally, before I did the steps above, I wanted to make sure that I had fully uninstalled node & npm. To do that, I followed the following steps from stackoverflow question 11177954, specifically from the answer by Dominic Tancredi, who says:

最后,在我执行上述步骤之前,我想确保我已经完全卸载了 node 和 npm。为此,我遵循了 stackoverflow 问题11177954 中的以下步骤,特别是来自 Dominic Tancredi 的回答,他说:

To recap, the best way (I've found) to completely uninstall node + npm is to do the following:

  1. go to /usr/local/lib and delete any node and node_modules
  2. go to /usr/local/include and delete any node and node_modules directory
  3. if you installed with brew install node, then run brew uninstall node in your terminal
  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
  5. go to /usr/local/bin and delete any node executable You may need to do the additional instructions as well:

总结一下,完全卸载 node + npm 的最佳方法(我发现)是执行以下操作:

  1. 转到 /usr/local/lib 并删除任何节点和 node_modules
  2. 转到 /usr/local/include 并删除任何节点和 node_modules 目录
  3. 如果您使用 brew install node 安装,则在终端中运行 brew uninstall node
  4. 检查您的主目录中是否有任何本地或 lib 或包含文件夹,并从那里删除任何节点或 node_modules
  5. 转到 /usr/local/bin 并删除任何节点可执行文件您可能还需要执行其他说明:
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules

I hope that is of help to someone :-)

我希望这对某人有帮助:-)

回答by ywplee

I had a similar issue with my mac. I did the followings to solve the problem.

我的 mac 也有类似的问题。我做了以下事情来解决这个问题。

  1. open 'Disk Utility' application
  2. select your hard drive.
  3. run verify disk permissions
  4. run repair disk permissions
  1. 打开“磁盘工具”应用程序
  2. 选择您的硬盘。
  3. 运行验证磁盘权限
  4. 运行修复磁盘权限

回答by suhailameen46

you need to chmod and change the file permission for all the files inside /Users//.config/configstore/

您需要 chmod 并更改 /Users//.config/configstore/ 中所有文件的文件权限

should work fine after that. Mac users may have to switch to root using su which they have to enable from system preferences before running chmod command.

在那之后应该可以正常工作。Mac 用户可能必须使用 su 切换到 root,他们必须在运行 chmod 命令之前从系统首选项启用。