Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Installation fails with npm 5 #707

Open
marklagendijk opened this issue Jun 1, 2017 · 43 comments
Open

Installation fails with npm 5 #707

marklagendijk opened this issue Jun 1, 2017 · 43 comments

Comments

@marklagendijk
Copy link

marklagendijk commented Jun 1, 2017

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:

  • OS: Ubuntu 16.04
  • Node: v6.10.3, installed via NodeSource
  • npm: 5.0.1
  • sudo npm install -g phantomjs-prebuilt, with default NodeSource installation, sudo is needed for installing global packages.
LeSuisse added a commit to Enalean/docker-tuleap-buildsrpms that referenced this issue Jun 7, 2017
phantomjs-prebuilt can not be installed globally with npm5
(see Medium/phantomjs#707)
LeSuisse added a commit to Enalean/docker-tuleap-test-karma that referenced this issue Jun 7, 2017
phantomjs-prebuilt can not be installed globally with npm5
(see Medium/phantomjs#707)
@atlastze
Copy link

using nodejs 7.x and npm 4 instead

@thomas-lee
Copy link

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
Copy link

edi9999 commented Jun 27, 2017

This is still happening with npm version 5.0.4

@fwh1990
Copy link

fwh1990 commented Jul 12, 2017

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

@felipecocco
Copy link

+1

3 similar comments
@ddolcimascolo
Copy link

+1

@MichaelBailly
Copy link

+1

@dbenchi
Copy link

dbenchi commented Jul 18, 2017

+1

@Nitro-N
Copy link

Nitro-N commented Jul 18, 2017

++

@bkarakashev
Copy link

+1

1 similar comment
@shehi
Copy link

shehi commented Jul 23, 2017

+1

@btoueg
Copy link

btoueg commented Jul 24, 2017

Please use the reaction feature of Github:

Reaction feature

@krisquigley
Copy link

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

@happilymarrieddad
Copy link

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

@JulienPalard
Copy link

Still happen with npm 5.3.0 and node v8.4.0

@JulienPalard
Copy link

JulienPalard commented Aug 31, 2017

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: npm/npm#17906

@happilymarrieddad
Copy link

happilymarrieddad commented Aug 31, 2017

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

@JulienPalard
Copy link

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

@bryanleetc
Copy link

@JulienPalard This worked for me in ansible

- name: Install phantomjs
      command: bash -lc "sudo npm install -g phantomjs-prebuilt --unsafe-perm"

@JulienPalard
Copy link

@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
Copy link

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!

Mikulas added a commit to manGoweb/mango-cli that referenced this issue Sep 11, 2017
Bypasses phantomjs privilege errors:
Medium/phantomjs#707
@simllll
Copy link

simllll commented Sep 13, 2017

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
Copy link
Author

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.

@danielfoxp2
Copy link

danielfoxp2 commented Jan 23, 2018

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
Copy link

S-mohan commented Mar 10, 2018

https://smohan.net/blog/me7esu

@tiamica
Copy link

tiamica commented Mar 26, 2018

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

This worked well for me on Ubuntu 16.04

@ortonomy
Copy link

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

@gsikorski
Copy link

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

@atomantic
Copy link

This worked for me:

FROM node:8.11.1
RUN npm i -g phantomjs-prebuilt --unsafe-perm --silent
...

@chengle123
Copy link

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

@BeanMc
Copy link

BeanMc commented Aug 6, 2018

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

@matusferko
Copy link

@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
Copy link

simllll commented Aug 17, 2018

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

@nickgrealy
Copy link

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
Copy link

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
Copy link

kcrisman commented Jan 8, 2019

Still happening - this time on Mac and

$ npm -v
6.4.1
$ node -v
v10.15.0

@nimatrazmjo
Copy link

I have same issue using docker

@kcrisman
Copy link

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

@S-mohan
Copy link

S-mohan commented Jul 12, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests