简体   繁体   English

sh:1:节点:权限被拒绝

[英]sh: 1: node: Permission denied

Tried to run this command on ubuntu 18.04尝试在 ubuntu 18.04 上运行此命令

npm install -g pngquant-bin

but I got this error,但我得到了这个错误,

[..................] | fetchMetadata: sill resolveWithNewModule npm-conf@1.1.3 checking installable status
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
/root/.nvm/versions/node/v10.8.0/bin/pngquant -> /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin/cli.js

> pngquant-bin@5.0.0 postinstall /root/.nvm/versions/node/v10.8.0/lib/node_modules/pngquant-bin
> node lib/install.js

sh: 1: node: Permission denied
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! pngquant-bin@5.0.0 postinstall: `node lib/install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the pngquant-bin@5.0.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-12T18_08_02_197Z-debug.log

Do you do you know how to deal with this?你知道如何处理这个吗? I tried every solution found in this articles yet not succeeded.我尝试了本文中找到的所有解决方案,但均未成功。

Got the same error sh: 1: node: Permission denied得到相同的错误sh: 1: node: Permission denied

So this worked for me所以这对我有用

npm config set user 0
npm config set unsafe-perm true

These issues happen because of broken packages.这些问题是由于包装损坏而发生的。 Go to the main folder.转到主文件夹。 If using Linux use command如果使用 Linux 使用命令

sudo rm -rf node_modules.

After that run this command if you are using yarn之后,如果您使用的是 yarn,请运行此命令

yarn install

If you are using npm run this command如果你使用 npm 运行这个命令

npm install

in fact, npm can't use root account to install anything.实际上, npm不能使用root帐户安装任何东西。 if you use root account, npm will create a non-permission account to install.如果您使用root帐户, npm将创建一个无权限帐户进行安装。 in this case, if the package need to execute writeFile or other operation which need permission, the error node: Permission denied will be raised.在这种情况下,如果包需要执行writeFile或其他需要权限的操作,则会出现错误node: Permission denied

so, you can choose optional arbitrary under:因此,您可以在以下选项中任意选择:

  • npm install xxx --unsafe-perm npm install xxx --unsafe-perm
  • npm config set unsafe-perm true npm config set unsafe-perm true
  • create high-permission account dedicate to execute npm install创建专用于执行npm install的高权限帐户

The /root/.npm/... log path in your original message shows you're already running as root, and (despite what others advise) I'd say this is most likely causing your problem.原始消息中的/root/.npm/...日志路径显示您已经以 root 身份运行,并且(尽管其他人建议)我会说这很可能导致您的问题。

My (limited) experience running Node as root is that most npm install runs get quite a long way, but then fail with some variation on the error you showed.我以 root 身份运行 Node 的(有限)经验是,大多数npm install运行都会有很长的路要走,但随后会因您显示的错误的一些变化而失败。 The only reliable solution I've found is to not run Node or npm as root at all on Ubuntu.我发现的唯一可靠的解决方案是根本不在 Ubuntu 上以 root 身份运行 Node 或 npm Just use a normal user account to download and unpack the Node installation.只需使用普通用户帐户下载并解压缩 Node 安装即可。

At least one problem with running as root for me turned out to be because some dependency-of-a-dependency npm install script was calling setuid to switch to a less-privileged user.对我来说,以 root 身份运行的至少一个问题是因为某些依赖关系的npm install脚本正在调用setuid以切换到特权较低的用户。 For some reason, it chose UID 500—which doesn't exist on Ubuntu—and consequently lost all its privileges.出于某种原因,它选择了 UID 500(在 Ubuntu 上不存在),因此失去了所有特权。 The 'Permission denied' errors were therefore because I was running as root;因此,“权限被拒绝”错误是因为我以 root 身份运行; setuid doesn't work for a normal user. setuid不适用于普通用户。

I believe this is related to Error: setuid user id does not exist npm ERR!我相信这与错误有关:setuid 用户 ID 不存在 npm ERR! when npm install forever -g .当 npm install forever -g 时

Delete the node_modules and install it again删除 node_modules 并重新安装

sudo rm -rf node_modules sudo rm -rf node_modules

npm install npm 安装

I make the chown to project user owner (in USERID) dir and resolv the "permission denied" problem:我将 chown 设置为项目用户所有者(在 USERID 中)目录并解决“权限被拒绝”问题:

sudo chown -R USERID.USERID * sudo chown -R USERID.USERID *

In my case it was a silly typo, I was forgotten to add node into the front of the start command in package.json .就我而言,这是一个愚蠢的错字,我忘记将node添加到package.json的 start 命令的前面。 So I've changed:所以我改变了:

"scripts": {
    "start": "app/server.js"
}

... to: ... 至:

"scripts": {
    "start": "node app/server.js"
}

此外(这可能对docker有用)您可以通过环境变量npm_config_user全局覆盖此配置设置——例如:

ENV npm_config_user=root

For Deploying with Docker:使用 Docker 部署:

  • make sure /node_modules is deleted or added to dockerignorefile确保/node_modules被删除或添加到 dockerignorefile
  • make sure /dist is deleted or added to dockerignorefile确保/dist被删除或添加到 dockerignorefile

the problem was solved for me by deleting both files and build them in the container通过删除两个文件并将它们构建在容器中为我解决了这个问题

I ran into the same error an nothing really helped.我遇到了同样的错误,没有任何帮助。 I found a medium article explaining how to set up an angular build management .我找到了一篇解释如何设置角度构建管理的中型文章 For some reason adding出于某种原因添加

- npm link @angular/cli@13.2.5

to my build script made it.我的构建脚本做到了。 I basically added all of the recommendations above.我基本上添加了上面的所有建议。 So my build script now looks like this所以我的构建脚本现在看起来像这样

- ...
- npm config set user 0
- npm config set unsafe-perm true
- npm i --force
- npm link @angular/cli@13.2.5
- ...

I hope it helps!我希望它有帮助! I would be happy if someone could explain why it actually worked.如果有人能解释为什么它确实有效,我会很高兴。

This is an old question but maybe someone still need some help.这是一个老问题,但也许有人仍然需要一些帮助。

This errors often is displayed because you have defined in the package.json just the path.由于您在 package.json 中仅定义了路径,因此通常会显示此错误。 For example:例如:

{
  // more definitions
  "scripts": {
    // other scripts
    "getPax8Products": "<filepath>",
    // more scripts
  },
  // more definitions
}

In this case, you need to:在这种情况下,您需要:

  1. Add the following lines in the very beggining of the script在脚本的开头添加以下行
#!/usr/bin/env node
'use strict';
  1. Give the file execution permission赋予文件执行权限
# in UNIX based
chmod +x <filepath>

You also can modify the package.json and add the node command.您还可以修改 package.json 并添加 node 命令。 However, you need to be aware that NPM will run in the script's directory:但是,您需要注意 NPM 将在脚本的目录中运行:

{
  // more definitions
  "scripts": {
    // other scripts
    "getPax8Products": "node <filepath>",
    // more scripts
  },
  // more definitions
}

For me, I had not installed my dependencies.对我来说,我没有安装我的依赖项。 node_modules did not exist, but I had jest installed globally apparently. node_modules 不存在,但显然我已经在全球范围内安装了 jest。 Running npm ci and then running npm test solved my issue.运行npm ci然后运行npm test解决了我的问题。

  1. npm install lite-server --save-dev

  2. packages.json : packages.json

     "scripts": { "dev": "lite-server", }, "devDependencies": { "lite-server": "^2.6.1" }
  3. npm run dev

I stuck with same issue when tried to install packages into AWS Sagemaker instance尝试将软件包安装到 AWS Sagemaker 实例时,我遇到了同样的问题

The issue coming because NPM by default install new global packages into ~/.npm-global When you run npm install -g by root, npm is try to install package into /root/.npm-global/..., and stuck with access denied. The issue coming because NPM by default install new global packages into ~/.npm-global When you run npm install -g by root, npm is try to install package into /root/.npm-global/..., and stuck with拒绝访问。

Simply workaround to re-config global folder for npm.简单的解决方法是为 npm 重新配置全局文件夹。 ( https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally ) https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Here is example of install obj2gltf这是安装 obj2gltf 的示例

mkdir /npm-global
npm config set prefix '/npm-global'
export PATH=/npm-global/bin:$PATH
npm install -g obj2gltf

I had that error too and tried the above solutions without any change.我也有这个错误并尝试了上述解决方案而没有任何改变。 My error was caused because I had Windows (11) with a WSL and NVM installed on both operating systems.我的错误是因为我在两个操作系统上都安装了 WSL 和 NVM 的 Windows (11)。 I had to uninstall NVM on my Windows to resolve the conflicts.我必须在我的 Windows 上卸载 NVM 才能解决冲突。

I think if you develop in your WSL and have a resource installed on both operating systems, a dependency might point to the wrong operating system with the resource (in my case to the NVM on Windows).我认为,如果您在 WSL 中开发并在两个操作系统上都安装了资源,则依赖项可能指向错误的操作系统与资源(在我的情况下指向 Windows 上的 NVM)。 The WSL user didn't have sufficient permissions to perform any execution on the Windows machine, which lead to the error. WSL 用户没有足够的权限在 Windows 机器上执行任何操作,从而导致错误。

您需要root用户权限,只需在命令前添加sudo关键字并输入您的密码

sudo npm install -g pngquant-bin

尝试在项目文件夹中安装节点

npm install node

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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