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

bin/postinstall.js fails when installing the runtime #119

Open
mortie opened this issue Jul 30, 2017 · 7 comments
Open

bin/postinstall.js fails when installing the runtime #119

mortie opened this issue Jul 30, 2017 · 7 comments

Comments

@mortie
Copy link

mortie commented Jul 30, 2017

I can't install this with npm. The output of sudo npm install -g qbrt:

vor ~ $ sudo npm install -g qbrt
/usr/bin/qbrt -> /usr/lib/node_modules/qbrt/bin/cli.js

> [email protected] postinstall /usr/lib/node_modules/qbrt
> node ./bin/postinstall.js

✗ Installing runtime … failed!
{ AssertionError [ERR_ASSERTION]: rimraf: missing path
    at rimraf (/usr/lib/node_modules/qbrt/node_modules/fs-extra/lib/remove/rimraf.js:35:3)
    at rimraf (/usr/lib/node_modules/qbrt/node_modules/universalify/index.js:5:67)
    at /usr/lib/node_modules/qbrt/node_modules/pify/index.js:29:7
    at Promise (<anonymous>)
    at /usr/lib/node_modules/qbrt/node_modules/pify/index.js:12:10
    at ret (/usr/lib/node_modules/qbrt/node_modules/pify/index.js:56:34)
    at Promise.resolve.then.then.then.then.then.then.then.then.then.then.catch.finally (/usr/lib/node_modules/qbrt/bin/install-runtime.js:261:27)
    at /usr/lib/node_modules/qbrt/node_modules/promise.prototype.finally/implementation.js:12:11
    at Promise (<anonymous>)
    at getPromise (/usr/lib/node_modules/qbrt/node_modules/promise.prototype.finally/implementation.js:11:9)
  generatedMessage: false,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '==' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node ./bin/postinstall.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall 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-07-30T14_16_24_901Z-debug.log

The complete /root/.npm/_logs/2017-07-30T14_16_24_901Z-debug.log file (with a .txt extension, because GitHub): 2017-07-30T14_16_24_901Z-debug.log.txt

@mortie mortie changed the title bin/postinstall.js fails when installing bin/postinstall.js fails when installing the runtime Jul 30, 2017
@mortie
Copy link
Author

mortie commented Jul 30, 2017

I forgot to include information about my system. Here it is:

  • OS: Arch Linux
  • node version: v8.2.1
  • NPM version: 5.3.0
  • uname -a: Linux vor 4.11.9-1-ARCH #1 SMP PREEMPT Wed Jul 5 18:23:08 CEST 2017 x86_64 GNU/Linux

@turbo
Copy link

turbo commented Jul 30, 2017

OS: Ubuntu

Installing runtime … failed!
{ [AssertionError: rimraf: missing path]
  name: 'AssertionError',
  actual: undefined,
  expected: true,
  operator: '==',
  message: 'rimraf: missing path',
  generatedMessage: false }
npm ERR! Linux 4.4.0-81-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "qbrt"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE

@turbo
Copy link

turbo commented Jul 30, 2017

I could fix this by upgrading node to exactly the version required:

nvm install 5.10.0
nvm use 5.10.0
npm install -g qbrt

@mykmelez
Copy link
Contributor

Per the stack trace, the code in qbrt that triggers the error is bin/install-runtime.js:261:27, which tries to delete the temporary directory that the post-install script uses:

    return pify(fs.remove)(tempDir);

The error message "rimraf: missing path" suggests that the temporary directory doesn't exist. But that's strange, because the fs.remove call is actually a call to fs-extra.remove, which says it behaves like rm -rf, so it shouldn't throw an error when deleting a nonexistent directory, per:

> mkdir foo
> ls -lad foo bar
ls: bar: No such file or directory
drwxr-xr-x  2 myk  staff  68 Jul 31 00:43 foo
> rm -rf foo bar
>

So I'm not sure what's happening here. However, it shouldn't be related to your version of Node. I can install qbrt on an Ubuntu machine using Node 8:

$ node --version && npm --version && sudo npm install -g qbrt
v8.2.1
5.3.0
/usr/bin/qbrt -> /usr/lib/node_modules/qbrt/bin/cli.js

> [email protected] postinstall /usr/lib/node_modules/qbrt
> node ./bin/postinstall.js

✓ Installing runtime … done!
/usr/lib
└── [email protected] 

I wonder if this has anything to do with outdated dependencies. Over in #124 I added testing for Node.js version 8, and Node 8 builds are failing with "Invalid Version: https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.1.tgz".

Meanwhile, over in #123 I'm switching from package-lock.json to npm-shrinkwrap.json, and I recreated that file from scratch (after merging a few updates to dependencies). I'll release version 0.2.1 after merging #123, after which I recommend trying again with Node 8 to see if it works for you!

@mykmelez
Copy link
Contributor

I've now updated qbrt to v0.2.1 after updating dependencies and switching from package-lock.json to npm-shrinkwrap.json. You should try reinstalling qbrt and see if it works now with Node 8.

I also took a look at the log file you referenced, and strangely, I don't see the same output you excerpted. There's no reference to install-runtime.js there; rather, this different error is reported:

3420 silly postinstall [email protected]
3421 info lifecycle [email protected]~postinstall: [email protected]
3422 verbose lifecycle [email protected]~postinstall: unsafe-perm in lifecycle false
3423 verbose lifecycle [email protected]~postinstall: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/usr/lib/node_modules/qbrt/node_modules/.bin:/usr/lib/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/home/martin/bin:/home/martin/.local/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/martin/.gem/ruby/2.3.0/bin
3424 verbose lifecycle [email protected]~postinstall: CWD: /usr/lib/node_modules/qbrt
3425 silly lifecycle [email protected]~postinstall: Args: [ '-c', 'node ./bin/postinstall.js' ]
3426 silly lifecycle [email protected]~postinstall: Returned: code: 1  signal: null
3427 info lifecycle [email protected]~postinstall: Failed to exec postinstall script
3428 verbose unlock done using /root/.npm/_locks/staging-a072192f34a17023.lock for /usr/lib/node_modules/.staging
3429 verbose stack Error: [email protected] postinstall: `node ./bin/postinstall.js`
3429 verbose stack Exit status 1

If the update doesn't fix the problem, then there may be something else going on, and we should investigate further.

@mortie
Copy link
Author

mortie commented Jul 31, 2017

Nothing changed with 0.2.1:

vor ~ $ sudo npm install -g qbrt
/usr/bin/qbrt -> /usr/lib/node_modules/qbrt/bin/cli.js

> [email protected] postinstall /usr/lib/node_modules/qbrt
> node ./bin/postinstall.js

✗ Installing runtime … failed!
{ AssertionError [ERR_ASSERTION]: rimraf: missing path
    at rimraf (/usr/lib/node_modules/qbrt/node_modules/fs-extra/lib/remove/rimraf.js:35:3)
    at rimraf (/usr/lib/node_modules/qbrt/node_modules/universalify/index.js:5:67)
    at /usr/lib/node_modules/qbrt/node_modules/pify/index.js:29:7
    at Promise (<anonymous>)
    at /usr/lib/node_modules/qbrt/node_modules/pify/index.js:12:10
    at ret (/usr/lib/node_modules/qbrt/node_modules/pify/index.js:56:34)
    at Promise.resolve.then.then.then.then.then.then.then.then.then.then.catch.finally (/usr/lib/node_modules/qbrt/bin/install-runtime.js:261:27)
    at /usr/lib/node_modules/qbrt/node_modules/promise.prototype.finally/implementation.js:31:16
    at <anonymous>
  generatedMessage: false,
  name: 'AssertionError [ERR_ASSERTION]',
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '==' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node ./bin/postinstall.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall 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-07-31T09_10_20_886Z-debug.log

Strangely, cloning the git repo (at commit 01ab20d) and running npm install locally works great. Also, running npm install qbrt works fine. Only installing it globally fails for some reason.

Another weird thing, which I haven't experienced with other npm modules, is that running sudo npm install -g . from a freshly cloned repository fails because it doesn't find the bin/postinstall.js script, even though both ~/src/qbrt/bin/postinstall.js and /usr/lib/node_modules/qbrt/bin/postinstall.js exists:

vor ~/src/qbrt $ sudo npm install -g .
/usr/bin/qbrt -> /usr/lib/node_modules/qbrt/bin/cli.js

> [email protected] postinstall /usr/lib/node_modules/qbrt
> node ./bin/postinstall.js

module.js:487
    throw err;
    ^

Error: Cannot find module '/home/martin/src/qbrt/bin/postinstall.js'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node ./bin/postinstall.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall 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-07-31T09_27_17_969Z-debug.log

If it wasn't for this, I would have tried to do some investigation myself, but since the issue can't be reproduced with local installs (without -g) and I can't install it globally from source, there's not much more I can do.

@mykmelez
Copy link
Contributor

mykmelez commented Aug 2, 2017

This reminds me of an issue I had installing Node modules in a Docker container. It might be because of how npm handles installation using sudo. Related issues from other projects include homebridge/homebridge#484 and nodejs/node-gyp#115.

If the issue you're experiencing is the same one, then adding --unsafe-perm to the install command should fix it, i.e. sudo npm install --unsafe-perm qbrt. However, in the long run, you should probably switch to an alternative to sudo, of which there are several.

One option is to change ownership of /usr/local/lib (or wherever NPM installs packages) to your user, which seems to be a popular option on macOS (probably because HomeBrew recommends it), i.e. chown -R YOUR_USERNAME /usr/local/lib (you might have to do this for /usr/local/bin as well, unsure).

A second option is to "use nvm", although I haven't found good documentation for what this means exactly, and nvm-sh/nvm#668 suggests that it could get cumbersome if you regularly switch between Node versions, since then "global" modules will be Node version-specific.

A third option is to create a user-specific directory for "global" modules and tell NPM to install them there instead, as described in the document Install npm packages globally without sudo on macOS and Linux.

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

3 participants