npm install puppeteer 显示权限被拒绝错误 [英] npm install puppeteer showing permission denied errors
问题描述
我无法将 puppeteer
作为项目依赖项安装,并且我尝试重新安装 node.js.任何人都知道如何解决这个问题?运行 Ubuntu 17.10 x64
I'm unable to install puppeteer
as a project dependency, and I've tried re-installing node. Anyone have an idea on how to fix this? Running Ubuntu 17.10 x64
sudo apt-get purge nodejs;
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -;
apt-get install -y nodejs;
sudo npm install -g n;
sudo n stable;
节点版本:
$ node -v
v9.4.0
$ npm -v
5.6.0
我尝试安装:
root@server:/var/www/html# npm install --save puppeteer
错误信息:
> puppeteer@1.1.0 install /var/www/html/node_modules/puppeteer
> node install.js
ERROR: Failed to download Chromium r536395! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: EACCES: permission denied, mkdir '/var/www/html/node_modules/puppeteer/.local-chromium'
errno: -13,
code: 'EACCES',
syscall: 'mkdir',
path: '/var/www/html/node_modules/puppeteer/.local-chromium' }
npm WARN project@1.0.0 No description
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@1.1.0 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer@1.1.0 install 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-02-19T15_55_52_669Z-debug.log
我在引用的问题中没有看到任何解决此问题的方法:https://github.com/GoogleChrome/puppeteer/issues/375
I don't see any ways to fix this in the referenced issue: https://github.com/GoogleChrome/puppeteer/issues/375
推荐答案
EDIT 20th April 2019:
lauraalvarezz1 建议的简单解决方案是,
The easy solution suggested by lauraalvarezz1 is,
sudo npm install -g puppeteer --unsafe-perm=true
只要您信任 puppeteer 并希望它在全球范围内安装 puppeteer,这就可以了.
This is okay as long as you trust puppeteer and want it to install puppeteer globally.
但是要注意使用 --unsafe-perm=true
来解决与权限相关的问题.原因是:
However beware of using --unsafe-perm=true
for permission related problems. Reasons are:
- 以非 root 用户身份使用 sudo 运行 unsafe-perm=true 将授予脚本 root 访问权限.仅当您信任脚本并且不太关心安全性时,这可能没问题.
- 您可能需要在您运行的每个脚本中使用
--no-sandbox
,因为如果没有此参数,使用此命令安装的 chrome 可能无法运行.请参阅此 github 问题.
- Running unsafe-perm=true with sudo, as a non-root user, will give the script root access. This might be okay only if you trust the script and do not concern about security that much.
- You might need to use
--no-sandbox
in every script you run, because the chrome installed with this command might not run without this parameter. See this github issue.
您已经使用 sudo
安装了 npm.因此,您全局安装的任何内容都需要 sudo
.
You have installed npm with sudo
. Thus anything you install globally will require sudo
.
要在 var/www/html
文件夹中安装任何东西,要么您必须拥有该文件夹,
To install anything on var/www/html
folder, either you have to own that folder,
sudo chown -R $USER /var/www/html
或者你可以使用 nvm 来管理 npm.从技术上讲,它将使用您的主目录和您当前的用户.
Or you can use nvm to manage npm. Technically it will use your home directory and your current user.
安装nvm后,就可以用它全局安装puppeteer了,
After installing nvm, you can install puppeteer globally with it,
npm i -g puppeteer
或者你必须使用 sudo
or you have to use sudo
sudo npm install --save puppeteer
但是由于权限错误,不会下载chromium,这就是为什么您必须使用---unsafe-perm=true
如前所述.
However chromium will not be downloaded due to permission error, that's why you have to use ---unsafe-perm=true
as stated before.
安全相关资源:
祝你好运!
这篇关于npm install puppeteer 显示权限被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!