1

I'm working with an old code base from an old project that uses bcrypt-as-promised (before bcrypt allowed the use of promises). When I try and npm install the package.json, I receive this error for that package:

npm WARN deprecated bcrypt-as-promised@1.1.0: the bcrypt module supports promises now, this module is no longer necessary

npm WARN deprecated bcrypt@0.8.7: bcrypt < v2.0.0 is susceptible to bcrypt wrap-around bug. Upgrade to bcrypt >= v2.0.0 for improved support for newer bcrypt hashes

And then proceeds to fail (I can paste more of the error message if needed).

I'm a little confused as to how I might be able to get this now deprecated package to install. I thought about modifying the codebase to only use bcrypt (with the now native promises supported), but I'm afraid of diving into a bee's nest and breaking the application. I was wondering first if there might be a way to install this package for the old code base to get it working.

Any thoughts? Thanks for your time and any insight you may have.

My package.json: https://github.com/twknab/mean_hike/blob/master/package.json

// Edit:

Here's the full terminal message I receive when I try and sudo npm install:

> bcrypt@0.8.7 install /var/www/mean_hike/node_modules/bcrypt
> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir 
'/var/www/mean_hike/node_modules/bcrypt/build'
gyp ERR! System Linux 4.4.0-1072-aws
gyp ERR! command "/usr/local/bin/node" 
"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/mean_hike/node_modules/bcrypt
gyp ERR! node -v v11.2.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@0.8.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@0.8.7 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/ubuntu/.npm/_logs/2018-11-27T10_46_27_925Z-debug.log
Community
  • 1
  • 1
twknab
  • 1,741
  • 1
  • 21
  • 35
  • 1
    These are just warnings, which shouldn't break the installation – can you add any more error detail? – Ben Nov 27 '18 at 09:43
  • @Ben Thanks for your response--I did add the full terminal message there. I tried installing `node-gyp` as well but I still get the same message. I also tried installing `node-gyp rebuild` as I see it mentioned in the error but again, receiving the same msg. Any insight you can provide would be immensely appreciated! :) – twknab Nov 27 '18 at 10:50

2 Answers2

1

Older versions of bcrypt can be quite tricky to install, and it looks like you're hitting a classic permissions issue with npm. You can try some of the tips listed in the official documentation here: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

… but in the meantime, here are a few things to try:

  1. Attempt a global install of node-gyp first, either with or without sudo: npm install node-gyp -g
  2. If that works, then try installing bcrypt (again, globally).
  3. If you're still seeing permissions issues, you may need to sort out ownership of your node_modules directory: sudo chown -r XXX /usr/lib/node_modules/ (assuming that's where the global modules directory is on your machine of course).
Ben
  • 7,548
  • 31
  • 45
  • Thx for your response. I did install `node-gyp` per your suggestions but have same issue. I tried changing global permissions for my `~/node_modules` and my `/var/www/mean_hike/node_modules` folder per [this thread](https://stackoverflow.com/a/16151707/6685623). When I tried running `sudo chown -r` and tried to supply permissions got msg that `-r` was not a valid flag? I have 2 `node_modules` folder on my ubuntu instance (both in project folder and the in root user dirs). Don't need `bcrypt-as-promised` globally per say. What should my `node_modules` (project folder) permissions be? – twknab Nov 27 '18 at 22:30
  • I also just tried: `sudo chown -R $USERNAME ./node_modules` (from within the project directory), and also `sudo chown -R $USERNAME ~/node_modules` (where the global folder lies). In my case $USERNAME = "ubuntu" (per AWS deployment)....wondering why I'm still hitting these permission errors...hmmm – twknab Nov 28 '18 at 00:31
  • I tried running: `sudo chown -R ubuntu ./*` (where `ubuntu` is system username) from within my project directory, and that seemed to work momentarily allowing me to `sudo npm install` without any errors. But when I tried to run the server it appeared the packages did not successfully install -- when I tried to manually install bcrypt or bcrypt-as-promised, e.g, `sudo npm install bcrypt -g --save` I got the same ole error...gunna have to step back and think more...really don't want to give up this code base entirely and just get her moving again even for a short while :D :D – twknab Nov 28 '18 at 00:55
  • 1
    Bizarre… I'm assuming there's nothing of note in `/home/ubuntu/.npm/_logs/2018-11-27T10_46_27_925Z-debug.log`? – Ben Nov 28 '18 at 13:01
  • It's so weird, it seems if I change the permissions nothing matters. I even tried switching to a different version of Node (that I had used back when building the project). I see some other stuff online about the EACCES: permission denied message in regards to bcrypt, but seems like some folks have different solutions (none of which are still working for me)....going to keep wrestling this in bits and see if I can figure out *why* and find a remedy. This project is a few years old running Ang1.x and I had put 100+ hours into it, just wanting to keep it alive a bit longer... =) – twknab Nov 29 '18 at 09:54
  • 1
    I ended up just using `yarn` to install my dependencies and it worked! I also ditched `bcrypt-as-promised` for `bcrypt` and I got my project running! Thank you for all of your help! – twknab Nov 30 '18 at 10:08
  • 1
    I found some insight into this issue from a month+ ago..looks like I originally installed my npm packages using `sudo`, because of this for some reason `bcrypt` specifically will have permission issues. I had to remove my `node_modules` and reinstall everything fresh without using sudo. I was then able to install bcrypt. I added this to my answer above, but just wanted to let you know unless you ever experience this again! Wishing you the best! – twknab Jan 13 '19 at 10:11
1

I found a solution to my issue was to use yarn to import all of my dependencies rather than npm, while also swapping bcrypt-as-promised for bcrypt (which now includes promises with no syntax changes necessary).

  1. I ditched bcrypt-as-promised and replaced it with bcrypt in my package.json file.

  2. I then changed any instance of require('bcrypt-as-promised') to require('bcrypt') (the syntax for using bcrypt remains the same, just the dependency importation lines need to change).

  3. Without using yarn, even after changing my folder permissions, I was still hitting permissions "EACCES: permission denied" errors, with only bcrypt failing. My versions of npm and node seemed fine. Made sure my Ubuntu box was all updated.

  4. That's when I gained the suggestion from a wise friend to try using yarn to grab the dependencies instead. I ran yarn import which reads the package.json file and creates a yarn.lock file. I then installed yarn on my ubuntu machine (sudo npm install yarn -g), and ran yarn install, and bcrypt successfully installed!

Update Jan 2019 - Improved Solution

It looks like if npm dependencies were originally installed using sudo, permission issues can be experienced when trying to install bcrypt. My improved solution was to:

  • Nuke the ./node_modules folder via sudo rm -r ./node_modules
  • Install npm packages fresh (not using sudo).
  • After this, I was able to npm i --save bcrypt with the package installing successfully.

Here's a link from GitHub that helped me find the solution and an excerpt:

@Mayocampo permission denied, mkdir '/home/someroute/node_modules/bcrypt/build'

It seems you run rpm as root, therrfore your account cannot mkdir under /home/someroute/node_modules/ Check dir with ls -l /home/someroute/node_modules/ Im sure owner of upper dir is root. or your account cannot have permission.

I guess there are two options are available.

  1. sudo rm -r ./node_modules And install package via npm again, but without using sudo.
  2. Change mod ./node_module to access and excutable. I decided first, and its fixed

Source: juicycool92 @ GitHub

twknab
  • 1,741
  • 1
  • 21
  • 35