npm错误!缺少脚本:开始_使用npm时如何解决“缺少写访问权限”错误

npm错误!缺少脚本:开始

The first time you try to install a package globally using npm, using the syntax npm install -g <package> on a Mac, or Linux, you might get a weird error, saying something like

第一次尝试在Mac或Linux上使用npm ,使用语法npm install -g <package>在全局npm install -g <package> ,您可能会遇到奇怪的错误,例如

Missing write access to /usr/local/lib/node_modules

npm error message

or something along those lines, followed by a long list of other errors of warnings, a consequence of the first error that’s printed to you.

或类似的内容,然后是一长串其他警告错误,这是打印到您的第一个错误的结果。

This error is preventing us to install the package.

此错误使我们无法安装软件包。

How do you fix this? It’s a permission error, which means you don’t have write access to that folder.

您如何解决这个问题? 这是一个权限错误,这意味着您没有对该文件夹的写权限。

This is how to solve it. Run this command:

这是解决方法。 运行以下命令:

sudo chown -R $USER /usr/local/lib/node_modules

Let’s break it down:

让我们分解一下:

sudo means we are running this command as root, the system super user. This is because we don’t have permission to write to that folder, but root will be able to fix any permission. This command also means the system will ask for your password to confirm.

sudo表示我们以root (系统超级用户)身份运行此命令。 这是因为我们没有写该文件夹的权限,但是root可以修复任何权限。 此命令还意味着系统将要求您输入密码以进行确认。

chown is the command we use to change the owner of a file or folder. We set the -R option to change the owner recursively, so we also get owner access to all the files already contained in there.

chown是我们用来更改文件或文件夹所有者的命令。 我们设置-R选项以递归方式更改所有者,因此我们还可以使所有者访问那里已经包含的所有文件。

$USER is an environment variable automatically set to your username.

$USER是自动设置为您的用户名的环境变量。

And the final piece is the folder path.

最后一块是文件夹路径。

Running this path will make the folder yours, so you can safely run your npm install -g <package> commands!

运行此路径将使该文件夹成为的文件夹,因此您可以安全地运行npm install -g <package>命令!

Pay attention to the folder listed by the error message. If it’s different, update the chown command accordingly.

请注意错误消息列出的文件夹。 如果不同,请相应地更新chown命令。

This tip applies to single user systems. On a multi-user system, you might want to create a dedicated directory for npm modules, see https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally.

本技巧适用于单用户系统。 在多用户系统上,您可能想为npm模块创建一个专用目录,请参阅https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

翻译自: https://flaviocopes.com/npm-fix-missing-write-access-error/

npm错误!缺少脚本:开始

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值