stoeffel / elmi-to-json

BSD 3-Clause "New" or "Revised" License
25 stars 10 forks source link

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

Open phluks opened 5 years ago

phluks commented 5 years ago

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

> elmi-to-json@0.19.0 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: fsevents@1.2.4 (node_modules/elm-test/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elmi-to-json@0.19.0 install: `binwrap-install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the elmi-to-json@0.19.0 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 commented 5 years ago

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

7817 silly install elmi-to-json@0.19.0
7818 info lifecycle elmi-to-json@0.19.0~install: elmi-to-json@0.19.0
7819 verbose lifecycle elmi-to-json@0.19.0~install: unsafe-perm in lifecycle false
7820 verbose lifecycle elmi-to-json@0.19.0~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 elmi-to-json@0.19.0~install: CWD: /usr/lib/node_modules/elm-test/node_modules/elmi-to-json
7822 silly lifecycle elmi-to-json@0.19.0~install: Args: [ '-c', 'binwrap-install' ]
7823 silly lifecycle elmi-to-json@0.19.0~install: Returned: code: 1  signal: null 
7824 info lifecycle elmi-to-json@0.19.0~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: fsevents@1.2.4 (node_modules/elm-test/node_modules/fsevents):
7830 warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: 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: elmi-to-json@0.19.0 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 elmi-to-json@0.19.0
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 elmi-to-json@0.19.0 install: `binwrap-install`
7841 error Exit status 1
7842 error Failed at the elmi-to-json@0.19.0 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 commented 5 years ago

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

$ sudo npm install -g elmi-to-json@0.19.0
/usr/local/bin/elmi-to-json -> /usr/local/lib/node_modules/elmi-to-json/bin/elmi-to-json

> elmi-to-json@0.19.0 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! elmi-to-json@0.19.0 install: `binwrap-install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the elmi-to-json@0.19.0 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 commented 5 years ago

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 commented 5 years ago

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

turboMaCk commented 5 years ago

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 commented 5 years ago

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 elmi-to-json@0.19.0
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 commented 5 years ago

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 https://github.com/avh4/binwrap/issues/21

malaire commented 4 years ago

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

phluks commented 4 years ago

Thanks @malaire. Looks good to me :-)

dptole commented 4 years ago

@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 commented 4 years ago

@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.