24

I had phantomjs installed on this machine before, but now it can't find the executable. So I uninstalled it (npm uninstall phantomjs, npm uninstall phantomjs-prebuild).

But installing it doesn't work. Could somebody please tell me why / how to fix it?

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

> [email protected] 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...
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
  [=======================================-] 98%
Received 22866K total.
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-1505979849548/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-1505979849548/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-1505979849548/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-1505979849548/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! [email protected] install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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/2017-09-21T07_44_13_695Z-debug.log

The log gives:

2467 silly install [email protected]
2468 info lifecycle [email protected]~install: [email protected]
2469 verbose lifecycle [email protected]~install: unsafe-perm in lifecycle false
2470 verbose lifecycle [email protected]~install: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/usr/lib/node_modules/phantomjs-prebuilt/node_modules/.bin:/usr/lib/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
2471 verbose lifecycle [email protected]~install: CWD: /usr/lib/node_modules/phantomjs-prebuilt
2472 silly lifecycle [email protected]~install: Args: [ '-c', 'node install.js' ]
2473 silly lifecycle [email protected]~install: Returned: code: 1  signal: null
2474 info lifecycle [email protected]~install: Failed to exec install script
2475 verbose unlock done using /root/.npm/_locks/staging-a072192f34a17023.lock for /usr/lib/node_modules/.staging
2476 verbose stack Error: [email protected] install: `node install.js`
2476 verbose stack Exit status 1
2476 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:280:16)
2476 verbose stack     at emitTwo (events.js:106:13)
2476 verbose stack     at EventEmitter.emit (events.js:191:7)
2476 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
2476 verbose stack     at emitTwo (events.js:106:13)
2476 verbose stack     at ChildProcess.emit (events.js:191:7)
2476 verbose stack     at maybeClose (internal/child_process.js:891:16)
2476 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
2477 verbose pkgid [email protected]
2478 verbose cwd /tmp
2479 verbose Linux 4.10.0-33-generic
2480 verbose argv "/usr/bin/nodejs" "/usr/bin/npm" "-g" "install" "phantomjs-prebuilt"
2481 verbose node v6.11.2
2482 verbose npm  v5.4.2
2483 error code ELIFECYCLE
2484 error errno 1
2485 error [email protected] install: `node install.js`
2485 error Exit status 1
2486 error Failed at the [email protected] install script.
2486 error This is probably not a problem with npm. There is likely additional logging output above.
2487 verbose exit [ 1, true ]

My System

  • Ubuntu 16.04
  • npm 5.4.2

5 Answers 5

28

Although it's a bit too late to answer this but still I would go on with it .

I got it to work by doing this

sudo npm install -g [email protected] --unsafe-perm

Check the comment here

0
10

I just got this mistake too and found 2 solutions:

  1. fix this via npm config change

    1. check your current npm-config (on linux npm config list --json | grep "user\|unsafe-perm")
    2. if nesseccary change your npm-config
      • npm config set user 0 The UID to set to when running package scripts as root.
      • npm config set unsafe-perm true Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.
  2. npmjs.com recommends switching to an npm version manager for this error, described within this article.

2
  • 5
    Wanted to say that setting npm config set user 0 totally fixed it for me. Thanks!
    – dmanexe
    Commented Mar 2, 2019 at 16:47
  • In my Dockerfile, this looked like ENV NPM_CONFIG_USER=0. Thanks!
    – Noumenon
    Commented Aug 4, 2021 at 2:07
4

Just a quick-fix:

# Install locally (in my case: ~/node_modules)
$ npm install phantomjs-prebuilt

# Add to path
$ cd ~/bin
~/bin$ ln -s ../node_modules/phantomjs-prebuilt/bin/phantomjs

# Check if it worked
$ phantomjs --version
2.1.1
1
  • I basically did the same thing, but I had to make sure it really is installed globally so I just moved the directories: sudo mv ~/node_modules/phantomjs /usr/lib/node_modules
    – TeeTrinker
    Commented Apr 11, 2018 at 1:14
0

I ran into this error while attempting to run npm ci inside Laravel Homestead.

For me, turning off SSL validation solved the issue:

npm set strict-ssl false

According to the docs, this tells NPM to skip validation of SSL keys, which might be necessary in corporate environments, where a proxy with a self-signed SSL certificate might be used to intercept encrypted traffic.

I'm pretty sure that in my case, there's no proxy, since I've never had any other SSL issues. It's probably just some weird side-effect of running npm inside a virtual machine.

0

in my case it was node_modules permission issue. try changing your node_modules folder permission

chown ubuntu:ubuntu -R node_modules //for ubuntu only

Note: you can check your folder permission using ls -la command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.