Open marklagendijk opened 7 years ago
using nodejs 7.x and npm 4 instead
I have the same issue even without sudo. And I found someone raised similar question.
This is still happening with npm version 5.0.4
That's a bad news. I can't use nodeJs8 just because I must run CI in phantomJs browser.
+1
+1
+1
+1
++
+1
+1
Please use the reaction feature of Github:
This may or may not help some of you, but using yarn global add phantomjs-prebuilt
works for me as a workaround.
I got it to work by doing this sudo npm install -g phantomjs@2.1.1 --unsafe-perm
Still happen with npm 5.3.0
and node v8.4.0
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.
@JulienPalard did you try sudo npm install -g phantomjs@2.1.1 --unsafe-perm that worked for me
@happilymarrieddad I'm using ansible, so I don't think I can pass the (undocumented?) --unsafe-perm flag :(
@JulienPalard This worked for me in ansible
- name: Install phantomjs
command: bash -lc "sudo npm install -g phantomjs-prebuilt --unsafe-perm"
@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.
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!
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
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.
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
@bryanleetc your answer is a great help for me.. Thanks ❤️
Fails for me on macOS 10.12.6, node 6.11.4, npm 5.5.1. Workaround with -unsafe-perm
works.
@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.
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.
sudo apt install phantomjs npm install -g app --ignore-scripts
This worked well for me on Ubuntu 16.04
+1 in 2018, trying to install phantomjs in docker container... I guess this will never be fixed...
Still occurring, node 8.11.1/ npm 5.8.0 or 5.6.0. Tested on Ubuntu 17.10 and 18.04.
This worked for me:
FROM node:8.11.1
RUN npm i -g phantomjs-prebuilt --unsafe-perm --silent
...
found the solution. https://smohan.net/blog/me7esu
a solution for phantomjs 1.9.8 version. https://gist.github.com/Djokic/8e5e023ae7bf97340bd6
@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
@coffy probably the script is outdated in the meantime, I really suggest you to use puppeteer though!
For me, I only had to change my Docker hub image from:
FROM node:10.12.0-alpine
to
FROM node:10.12.0
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.
Still happening - this time on Mac and
$ npm -v
6.4.1
$ node -v
v10.15.0
I have same issue using docker
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.
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
rm -rf ./node_modules npm install --unsafe-perm npm run build
Installation of phantomjs-prebuilt started failing after upgrading to npm from 3.x to 5.0.1
I am using:
sudo npm install -g phantomjs-prebuilt
, with default NodeSource installation,sudo
is needed for installing global packages.