Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install error: unpacked_bin is deleted before it's used #20

Open
phluks opened this issue Dec 10, 2018 · 11 comments
Open

Install error: unpacked_bin is deleted before it's used #20

phluks opened this issue Dec 10, 2018 · 11 comments

Comments

@phluks
Copy link

phluks commented Dec 10, 2018

I try to install elm-test, that relies on elmi-to-json:

sudo npm install -g elm-test
/usr/bin/elm-test -> /usr/lib/node_modules/elm-test/bin/elm-test

> [email protected] install /usr/lib/node_modules/elm-test/node_modules/elmi-to-json
> binwrap-install

ERR Error extracting https://github.com/stoeffel/elmi-to-json/releases/download/0.19.0/elmi-to-json-0.19.0-linux.tar.gz - Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/elm-test/node_modules/elmi-to-json/unpacked_bin'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/elm-test/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `binwrap-install`
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!     /home/olav/.npm/_logs/2018-12-10T13_40_27_715Z-debug.log

If I attempt to create the dir with:
sudo mkdir -p /usr/lib/node_modules/elm-test/node_modules/elmi-to-json/unpacked_bin
It is deleted before it is used when i run:
sudo npm install -g elm-test
It looks like a race-condition.

@phluks
Copy link
Author

phluks commented Dec 10, 2018

Here is the elmi-to-json part of the debug.log if it helps.

7817 silly install [email protected]
7818 info lifecycle [email protected]~install: [email protected]
7819 verbose lifecycle [email protected]~install: unsafe-perm in lifecycle false
7820 verbose lifecycle [email protected]~install: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/usr/lib/node_modules/elm-test/node_modules/elmi-to-json/node_modules/.bin:/usr/lib/node_modules/elm-test/node_modules/.bin:/usr/lib/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
7821 verbose lifecycle [email protected]~install: CWD: /usr/lib/node_modules/elm-test/node_modules/elmi-to-json
7822 silly lifecycle [email protected]~install: Args: [ '-c', 'binwrap-install' ]
7823 silly lifecycle [email protected]~install: Returned: code: 1  signal: null 
7824 info lifecycle [email protected]~install: Failed to exec install script
7825 timing action:install Completed in 330ms
7826 verbose unlock done using /home/olav/.npm/_locks/staging-a072192f34a17023.lock for /usr/lib/node_modules/.staging
7827 timing stage:rollbackFailedOptional Completed in 252ms
7828 timing stage:runTopLevelLifecycles Completed in 11169ms
7829 warn optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/elm-test/node_modules/fsevents):
7830 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7831 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
7831 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any  
7831 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   linux
7831 verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
7832 verbose stack Error: [email protected] install: `binwrap-install`
7832 verbose stack Exit status 1
7832 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
7832 verbose stack     at emitTwo (events.js:126:13)
7832 verbose stack     at EventEmitter.emit (events.js:214:7)
7832 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
7832 verbose stack     at emitTwo (events.js:126:13)
7832 verbose stack     at ChildProcess.emit (events.js:214:7)
7832 verbose stack     at maybeClose (internal/child_process.js:915:16)
7832 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
7833 verbose pkgid [email protected]
7834 verbose cwd /home/olav/tmp
7835 verbose Linux 4.15.0-42-generic
7836 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "elm-test"
7837 verbose node v8.14.0
7838 verbose npm  v6.4.1
7839 error code ELIFECYCLE
7840 error errno 1
7841 error [email protected] install: `binwrap-install`
7841 error Exit status 1
7842 error Failed at the [email protected] install script.
7842 error This is probably not a problem with npm. There is likely additional logging output above.
7843 verbose exit [ 1, true ]

@aligusnet
Copy link

It failed on macOS if I tried to install elmi-to-json only:

$ sudo npm install -g [email protected]
/usr/local/bin/elmi-to-json -> /usr/local/lib/node_modules/elmi-to-json/bin/elmi-to-json

> [email protected] install /usr/local/lib/node_modules/elmi-to-json
> binwrap-install

ERR Error extracting https://github.com/stoeffel/elmi-to-json/releases/download/0.19.0/elmi-to-json-0.19.0-osx.tar.gz - Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/elmi-to-json/unpacked_bin'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `binwrap-install`
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!     /Users/ai/.npm/_logs/2018-12-22T12_39_13_545Z-debug.log

@stoeffel
Copy link
Owner

stoeffel commented Jan 2, 2019

I think this is a binwrap problem and not a elmi-to-json issue. binwrap is used to install the binary.
Additionally, I thought that you shouldn't have to use sudo with npm install.

@avh4
Copy link
Collaborator

avh4 commented Apr 26, 2019

Has anyone been able to figure out what binwrap could be doing differently that would avoid this problem?

@turboMaCk
Copy link
Contributor

I agree with @stoeffel. The problem is the need for sudo. Seems that npm itself runs as root and therefore has write access to a directory but npm scripts must have different owner who has no write rights.

I think it's a very very very bad idea to run arbitrary scripts pulled from the internet (npm) as a root.

@malaire
Copy link

malaire commented Oct 19, 2019

I'm getting this same error in Debian 10 "buster" when installing with sudo.

Installing without sudo also fails, but with different error. (Initial warning here is known bug in Debian.)

malaire@box:~$ npm install -g [email protected]
npm WARN npm npm does not support Node.js v10.15.2
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
npm WARN checkPermissions Missing write access to /usr/local/lib
npm ERR! path /usr/local/lib
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/malaire/.npm/_logs/2019-10-19T14_14_34_209Z-debug.log

@avh4
Copy link
Collaborator

avh4 commented Oct 19, 2019

Ah, okay, so the issue seems to be that $NODE_HOME/elmi-to-json is owned by root, but then the install script (or the wrapper script itself if you install with scripts disabled) can't create a folder there (and also couldn't download or modify files there) -- does that sound right?

The planned fix for that in binwrap is that if it doesn't have write access there then it should fallback to unpacking the binaries somewhere under ${XDG_CACHE_HOME:-$HOME/.cache}, but no one has spent the time to implement that yet.

I'm gonna add these notes to avh4/binwrap#21

@malaire
Copy link

malaire commented Dec 4, 2019

Work-around is to change npm global install directory:
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

@phluks
Copy link
Author

phluks commented Dec 4, 2019

Thanks @malaire. Looks good to me :-)

@dptole
Copy link

dptole commented Feb 27, 2020

@avh4 On docker image node:12-alpine

npm i -g elm-test

image

To "fix"...

npm i -g --unsafe elm-test

image

Apparently the option --unsafe isn't documented (https://docs.npmjs.com/misc/config#unsafe-perm), but it works anyway... I imagine there is some kind of inferring going on

If that is the case the correct command should be npm i -g --unsafe-perm elm-test

@turboMaCk
Copy link
Contributor

@dptole I believe this can be fixed by adding elm-test to projects dependencies (package.json) and using npx elm-format or calling bin within node_modules ./node_modules/.bin/elm-format.

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

No branches or pull requests

7 participants