Medium / phantomjs

NPM wrapper for installing phantomjs
Other
1.42k stars 436 forks source link

Installation fails with npm 5 #707

Open marklagendijk opened 7 years ago

marklagendijk commented 7 years ago

Installation of phantomjs-prebuilt started failing after upgrading to npm from 3.x to 5.0.1

sudo npm install -g phantomjs-prebuilt
/usr/bin/phantomjs -> /usr/lib/node_modules/phantomjs-prebuilt/bin/phantomjs

> phantomjs-prebuilt@2.1.14 install /usr/lib/node_modules/phantomjs-prebuilt
> node install.js

Considering PhantomJS found at /usr/bin/phantomjs
Looks like an `npm install -g`
Could not link global install, skipping...
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /usr/lib/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1496325965675/phantomjs-2.1.1-linux-x86_64 -> /usr/lib/node_modules/phantomjs-prebuilt/lib/phantom
Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1496325965675/phantomjs-2.1.1-linux-x86_64' -> '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom'
    at Error (native)
  errno: -13,
  code: 'EACCES',
  syscall: 'link',
  path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1496325965675/phantomjs-2.1.1-linux-x86_64',
  dest: '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1496325965675/phantomjs-2.1.1-linux-x86_64' -> '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom'
    at Error (native)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.14 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the phantomjs-prebuilt@2.1.14 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I am using:

atlastze commented 7 years ago

using nodejs 7.x and npm 4 instead

thomas-lee commented 7 years ago

I have the same issue even without sudo. And I found someone raised similar question.

https://stackoverflow.com/questions/44499555/deploy-angularjs-app-into-docker-container#comment76322854_44499555

edi9999 commented 7 years ago

This is still happening with npm version 5.0.4

fwh1990 commented 7 years ago

That's a bad news. I can't use nodeJs8 just because I must run CI in phantomJs browser.

felipecocco commented 7 years ago

+1

ddolcimascolo commented 7 years ago

+1

MichaelBailly commented 7 years ago

+1

dbenchi commented 7 years ago

+1

Nitro-N commented 7 years ago

++

bkarakashev commented 7 years ago

+1

shehi commented 7 years ago

+1

btoueg commented 7 years ago

Please use the reaction feature of Github:

Reaction feature

krisquigley commented 7 years ago

This may or may not help some of you, but using yarn global add phantomjs-prebuilt works for me as a workaround.

happilymarrieddad commented 7 years ago

I got it to work by doing this sudo npm install -g phantomjs@2.1.1 --unsafe-perm

JulienPalard commented 7 years ago

Still happen with npm 5.3.0 and node v8.4.0

JulienPalard commented 7 years ago

Looks like the copy of the uncompressed directory is moved using fs.move which is from fs-extra which uses fs.link itself using the link syscall as:

link("/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1504184336394/phantomjs-2.1.1-linux-x86_64", "/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom") = -1 EACCES (Permission denied)

EACCES meaning according to the manpage:

EACCES Write access to the directory containing newpath is denied, or search  permis-
       sion  is  denied  for  one of the directories in the path prefix of oldpath or
       newpath.  (See also path_resolution(7).)

Which is expected as this section is ran as the nobody user and those directories are owned by root.

I'm not a npm guy enough to tell how it should work though.

see: https://github.com/npm/npm/issues/17906

happilymarrieddad commented 7 years ago

@JulienPalard did you try sudo npm install -g phantomjs@2.1.1 --unsafe-perm that worked for me

JulienPalard commented 7 years ago

@happilymarrieddad I'm using ansible, so I don't think I can pass the (undocumented?) --unsafe-perm flag :(

bryanleetc commented 7 years ago

@JulienPalard This worked for me in ansible

- name: Install phantomjs
      command: bash -lc "sudo npm install -g phantomjs-prebuilt --unsafe-perm"
JulienPalard commented 7 years ago

@bryanleetc Yes command will work but always mark as changed, so it's not the right way to do it. My official fix for the moment is: Do not install phantomjs globally, install it per-project as needed.

jeff1985 commented 7 years ago

OMG this issue costed me 3 hours of googling. Solved by --unsafe-perm but not really easy to understand... Please fix this if possible to help people save time and nerves!

simllll commented 7 years ago

If someone uses Elastic Beanstalk (Node 8), adding this .ebextensions file let it work again ;) (also uses the --unsafe-perm "hack")

files:
  "/opt/elasticbeanstalk/env.vars":
    mode: "000775"
    owner: root
    group: users
    content: |
      #!/bin/bash
      # Defines variables for use by the other scripts below.

      EB_NODE_VERSION=$(/opt/elasticbeanstalk/bin/get-config optionsettings -n aws:elasticbeanstalk:container:nodejs -o NodeVersion)

      # Exported to make sure Node binaries can be found by npm when we run it.
      # And this lets us invoke npm more simply too.
      export PATH=/opt/elasticbeanstalk/node-install/node-v$EB_NODE_VERSION-linux-x64/bin:$PATH

      # For parity with EB https://gist.github.com/wearhere/de51bb799f5099cec0ed28b9d0eb3663#file-ebnode-py-L147
      # and because some npm packages require HOME. This will also get npm to
      # read its configuration from the proper directory.
      export HOME=$(/opt/elasticbeanstalk/bin/get-config container -k app_user_home)

      EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
      EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)

      # Export the user's environment variables for use with npm, both because
      # EB does it https://gist.github.com/wearhere/de51bb799f5099cec0ed28b9d0eb3663#file-ebnode-py-L150
      # as well as because we might need NPM_TOKEN.
      #
      # I wish this was a heredoc but I can't get the syntax right in YAML,
      # EB gives an error "warning: here-document delimited by end-of-file (wanted `EOS`)"
      eval $(node -e "var vars = JSON.parse('$(/opt/elasticbeanstalk/bin/get-config environment)'); console.log(Object.keys(vars).map((key) => \`export \${key}=\"\${vars[key]}\"\`).join('\n'));")

  "/opt/elasticbeanstalk/hooks/appdeploy/pre/45npm_upgrade.sh":
    mode: "000755"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash
      #
      # Upgrade to latest npm

      . /opt/elasticbeanstalk/env.vars

      if [ $(npm -v) != "5.3.0" ]; then
        echo "Downgrading npm to 5.3.0..."
        npm upgrade npm@latest -g
      else
        echo "npm already at 5.3.0"
      fi

  "/opt/elasticbeanstalk/hooks/appdeploy/pre/46cache_node_modules.sh":
    mode: "000755"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash
      #
      # Cache Node modules in /var.

      . /opt/elasticbeanstalk/env.vars

      CACHE_DIR=/var/node_modules

      if [ ! -d $CACHE_DIR ]; then
        mkdir $CACHE_DIR
      fi
      ln -s $CACHE_DIR $EB_APP_STAGING_DIR

  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh":
    mode: "000755"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash
      #
      # Only install modules, don't rebuild like Elastic Beanstalk does by default:
      # https://gist.github.com/wearhere/de51bb799f5099cec0ed28b9d0eb3663.
      # New modules will be built when they are installed, and cached modules don't
      # need to be rebuilt. When the Node version changes, the configdeploy script
      # will rebuild.
      #
      # Note that this *overwrites* Elastic Beanstalk's default 50npm.sh script.

      . /opt/elasticbeanstalk/env.vars

      cd $EB_APP_STAGING_DIR && npm install --unsafe-perm --production

  "/opt/elasticbeanstalk/hooks/appdeploy/pre/55npm_cleanup.sh":
    mode: "000755"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash
      #
      # Remove all npm tmp files leftover by npm shrinkwrap flow.
      # https://github.com/npm/npm/issues/6855

      rm -rf /tmp/npm-*

  "/opt/elasticbeanstalk/hooks/configdeploy/pre/50npm.sh":
    mode: "000755"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash
      #
      # Only rebuild modules, don't install like Elastic Beanstalk tries to do
      # by default: https://gist.github.com/wearhere/de51bb799f5099cec0ed28b9d0eb3663.
      # package.json isn't changing on a config deploy, and all the existing
      # modules should be cached.
      #
      # Note that this *overwrites* Elastic Beanstalk's default 50npm.sh script.
      # But their default script actually doesn't work at all, since the app
      # staging dir, where they try to run `npm install`, doesn't exist during
      # config deploys, so ebnode.py just aborts:
      # https://gist.github.com/wearhere/de51bb799f5099cec0ed28b9d0eb3663#file-ebnode-py-L140

      . /opt/elasticbeanstalk/env.vars

      cd $EB_APP_DEPLOY_DIR && npm rebuild --unsafe-perm --production
marklagendijk commented 7 years ago

Note for everyone running into this: both Chrome and Firefox now support headless mode. With this PhantomJS has come to the end of its days, because there is no need for it anymore. You can now use Chrome, Chromium or Firefox for any scenario where you would otherwise use PhantomJS.

fabriziosalmi commented 6 years ago

Debian 8

curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs
npm -g install phantomjs-prebuilt --upgrade --unsafe-perm
AshishkrGoyal commented 6 years ago

@bryanleetc your answer is a great help for me.. Thanks ❤️

paulschreiber commented 6 years ago

Fails for me on macOS 10.12.6, node 6.11.4, npm 5.5.1. Workaround with -unsafe-perm works.

TiBeN commented 6 years ago

@marklagendijk Thanks for the information but this is not relevant (at least for now) when phantomjs is needed as a dependency of another 'useful' tool.

danielfoxp2 commented 6 years ago

Still happening in 2018 under docker container, node 8 and npm 5.6.0. Is this not a phantomjs issue? Is there an official answer of what to do? Is this not important?

I was able to install with --unsafe-perm though.

S-mohan commented 6 years ago

https://smohan.net/blog/me7esu

tiamica commented 6 years ago

sudo apt install phantomjs npm install -g app --ignore-scripts

This worked well for me on Ubuntu 16.04

ortonomy commented 6 years ago

+1 in 2018, trying to install phantomjs in docker container... I guess this will never be fixed...

gsikorski commented 6 years ago

Still occurring, node 8.11.1/ npm 5.8.0 or 5.6.0. Tested on Ubuntu 17.10 and 18.04.

atomantic commented 6 years ago

This worked for me:

FROM node:8.11.1
RUN npm i -g phantomjs-prebuilt --unsafe-perm --silent
...
chengle123 commented 6 years ago

found the solution. https://smohan.net/blog/me7esu

BeanMc commented 6 years ago

a solution for phantomjs 1.9.8 version. https://gist.github.com/Djokic/8e5e023ae7bf97340bd6

matusferko commented 6 years ago

@simllll your 'crazy' configuration file didnt work form me. Trying on 64bit Amazon Linux/4.5.2 node 8.11.3. Installation was successful with selecting node 7.10.1 on the sami AMI version but with version 8 it fails

simllll commented 6 years ago

@coffy probably the script is outdated in the meantime, I really suggest you to use puppeteer though!

nickgrealy commented 5 years ago

For me, I only had to change my Docker hub image from:

FROM node:10.12.0-alpine

to

FROM node:10.12.0
wonmaungthein commented 5 years ago

This may or may not help some of you, but using yarn global add phantomjs-prebuilt works for me as a workaround.

Thank you so much. I had been trying to solve that with npm and didn't work out. But with your suggestion, it works well.

kcrisman commented 5 years ago

Still happening - this time on Mac and

$ npm -v
6.4.1
$ node -v
v10.15.0
nimatrazmjo commented 5 years ago

I have same issue using docker

kcrisman commented 5 years ago

As a note, see https://github.com/ariya/phantomjs/issues/15344 where phantomjs itself has suspended development and been archived, though it seems more likely this is npm-related.

S-mohan commented 5 years ago

https://smohan.net/blog/me7esu

wget https://npm.taobao.org/mirrors/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2

tar -jxvf phantomjs-2.1.1-linux-x86_64.tar.bz2

vim /etc/profile

export PATH=$PATH:/usr/local/phantomjs-2.1.1-linux-x86_64/bin

source /etc/profile

in your project

rm -rf ./node_modules npm install --unsafe-perm npm run build