puppeteer/puppeteer

npm install -g puppeteer fails

umpox opened this issue ยท 26 comments

umpox commented

npm install -g puppeteer returns the following error: Download failed: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/puppeteer/.local-chromium'

Is this expected? I am using it as a dependency of a project I would like to install globally and this is blocking that.

Seems like your global modules are being installed in a place that requires some elevated access. Have you had EACCES issues before? Might consider having global modules installed in a less sensitive place (https://medium.com/@sifium/using-npm-install-without-sudo-2de6f8a9e1a3). Otherwise you might need sudo...

You shouldn't install things globally because they are dependencies. Packages when you install will install all of their dependencies internally. Only install things globally when you use them in your OS level tooling. And even then, quite a bit of tools like eslint and stylelint are well thought through in most tools to not need global installs of them.

You'd need to do sudo here though if you really wanted to do it, because /usr requires elevated permission to read/write to. But once again, don't do this. It's bad for your health later in life.

I am using it as a dependency of a project I would like to install globally and this is blocking that.

This might be an issue in the installation script that uses default umask for directory creation. I'll take a look.

Looks like this is related to npm permissions

This could've been caused by an npm bug that was fixed in: https://github.com/npm/npm/releases/tag/v5.4.1

Hmm... I use Win 10 with WSL and start getting these every now and then.
E.g. I run yarn in a new project which uses puppeteer and later I run yarn again I currently get An unexpected error occurred: "EIO: i/o error, unlink '/mnt/c/Users/foo/workspace/ui.form/node_modules/puppeteer/.local-chromium/linux-508693/chrome-linux/chrome'. I'll try to investigate further.

This command ended up working for me, in case anyone lands here by googling the error:

sudo npm install -g puppeteer --unsafe-perm=true

sudo npm i npm@4 -g

If someone does not work,
use npm@4.6.1 and it will work.
(In my case it worked perfectly.)

The --unsafe-perm flag lets Puppeteer-based tools install with sudo, but afterwards I'm having problems running the program:

$ my-stupid-tool
Launching Puppeteer...
Failed Error: spawn EACCES
    at ChildProcess.spawn (internal/child_process.js:330:11)
    at Object.exports.spawn (child_process.js:500:9)
    at Function.launch (/usr/lib/node_modules/oracle-cli/node_modules/puppeteer/lib/Launcher.js:106:40)
    at <anonymous>

And sudo my-stupid-tool seems to annoy Chromium and launching just times out.

Is telling users to not use system-wide node the only option here?

Still a bug with npm 6.1.0 && node 10.6.0 on Ubunutu 18.10
but can confirm the workaround is #375 (comment)

As @aslushnikov stated earlier, this is indeed related to npm permissions and fixing those gets rid of the error. In my case puppeteer was installed as a regular project dependency and fixing the npm permissions solved the problem.

I'm not sure that was the issue, I'm using NVM which sets correct npm package permissions (to my knowledge) but I could be wrong.

I'm using docker and amazonlinux image. Everything runs on root there as no one has time to bother, it's docker and it's for dev. But this error still occurs, npm perm fix has nothing to do with it in my case, also as in comment mentioned --unsafe-perm makes it pass thru install, but breaks the library usage.

npm -v: 5.6.0
node -v: v8.11.3

Docker file to reproduce:

FROM amazonlinux:2018.03.0.20180622

RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -

RUN REQUIREMENTS="\
  gcc-c++ \
  make \
  nodejs" \
  && yum install $REQUIREMENTS -y

RUN npm i -g codeceptjs@^1.2.1 puppeteer@^1.4.0

Build command: docker build - < Dockerfile

I believe this is an issue with permissions via NPM. I'm also using nvm with node 8.11.3 LTS, and npm 6.3.0 on a Mac.

@kat-whittenburg 's solution was what worked for me, as it bypasses the permissions. I was doing this locally however, so it still works if you omit the global flag.

sudo npm install puppeteer --unsafe-perm=true.

Thank you @kat-whittenburg !

Not a permanent fix, as I still run into permission errors on other packages (I've tried reseting everything, and I think it may have to do with using your fingerprint as a user access), but it works for individual items!

Try with:
sudo su
sudo npm i puppeteer (or with -g)
Yeah, both times with "sudo".

#375 (comment) works for me with no side effects

After trying sudo npm install puppeteer --unsafe-perm=true I still get the following error?

npm WARN engine puppeteer@1.12.2: wanted: {"node":">=6.4.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine mime@2.4.0: wanted: {"node":">=4.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine https-proxy-agent@2.2.1: wanted: {"node":">= 4.5.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine agent-base@4.2.1: wanted: {"node":">= 4.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
\
> puppeteer@1.12.2 install /volume1/projects/node_modules/puppeteer
> node install.js

sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! puppeteer@1.12.2 install: `node install.js`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the puppeteer@1.12.2 install script.
npm ERR! This is most likely a problem with the puppeteer package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls puppeteer
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 4.4.59+
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "puppeteer" "--unsafe-perm=true"
npm ERR! cwd /volume1/projects
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /volume1/projects/npm-debug.log
npm ERR! not ok code 0

On Debian, any idea how to deal?

@markedphillips The initial lines in your output tell you exactly why it doesn't work:

npm WARN engine puppeteer@1.12.2: wanted: {"node":">=6.4.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine mime@2.4.0: wanted: {"node":">=4.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine https-proxy-agent@2.2.1: wanted: {"node":">= 4.5.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine agent-base@4.2.1: wanted: {"node":">= 4.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})

You need to update your node and npm versions. How to do that properly, depends on what exactly you want to be able to do. Plenty of tutorials are around on how to do that.

mjlan commented

This command ended up working for me, in case anyone lands here by googling the error:

sudo npm install -g puppeteer --unsafe-perm=true

puppeteer@1.16.0 install /usr/local/lib/node_modules/puppeteer
node install.js

ERROR: Failed to download Chromium r656675! Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" env variable to skip download.
{ Error: connect ETIMEDOUT 216.58.220.208:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
-- ASYNC --
at BrowserFetcher. (/usr/local/lib/node_modules/puppeteer/lib/helper.js:110:27)
at Object. (/usr/local/lib/node_modules/puppeteer/install.js:64:16)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '216.58.220.208',
port: 443 }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! puppeteer@1.16.0 install: node install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the puppeteer@1.16.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I've been able to install with sudo npm install -g puppeteer --unsafe-perm=true but now I get -bash: puppeteer: command not found when trying to use it.

Yes, my PATH is configured properly and this is the only global NPM module that doesn't work.

While sudo npm install -g puppeteer --unsafe-perm=true might work (and kudos for working it out BTW). I don't think we can say the issue is closed. At best we can say "The issue has been dodged by setting an unsafe flag". It would be better if the install could be done in a proper, safe way.

Definitely agree there. The command may have worked for me (and, it seems, quite a few other people), but it's in the end a workaround and plays fast and loose with permissions. A true fix is definitely still needed.

tried everything, still the same error :((

it's throwing the error because mkdir '/usr/local/lib/node_modules/puppeteer/.local-chromium' should be mkdir -p '/usr/local/lib/node_modules/puppeteer/.local-chromium'

the .local-chromium directory it's trying to make is going into the /usr/local/lib/node_modules/puppeteer/ folder, which doesn't exist at the time it's running that command.

rfwn commented

Try using a proxy if the error is 403

In my case, changing the owner and group of ~/.npm and the directory of the node_modules to user works.
sudo chown -R your_user_name:your_user_name ~/.npm
sudo chown -R your_user_name:your_user_Name parent_dir_of_node_modules