node.bcrypt.js: Error when installing bcrypt with node 15

The bcrypt version I use is 5.0.0 and my OS is macOS 11.1

$ node -v
v15.5.1

I followed a suggestion in https://github.com/nodejs/node-gyp/issues/2245 to force/global install bcrypt but it didn’t work out as well. In both cases, the error message is the same

$ npm install --force --global bcrypt@latest

npm WARN using --force Recommended protections disabled.

added 68 packages, and audited 69 packages in 8s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

$ npm i
npm ERR! code 1
npm ERR! path /Users/xxx/Projects/zzz/node_modules/bcrypt
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@15.5.1 | darwin | x64
npm ERR! gyp info find Python using Python version 3.9.1 found at "/usr/local/opt/python@3.9/bin/python3.9"
npm ERR! gyp info spawn /usr/local/opt/python@3.9/bin/python3.9
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/xxx/.nvm/versions/node/v15.5.1/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/xxx/Projects/zzz/node_modules/bcrypt/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/xxx/.nvm/versions/node/v15.5.1/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/xxx/Library/Caches/node-gyp/15.5.1/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/xxx/Library/Caches/node-gyp/15.5.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/xxx/.nvm/versions/node/v15.5.1/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/xxx/Library/Caches/node-gyp/15.5.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/xxx/Projects/zzz/node_modules/bcrypt',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Users/xxx/.nvm/versions/node/v15.5.1/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:376:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:284:12)
npm ERR! gyp ERR! System Darwin 20.2.0
npm ERR! gyp ERR! command "/Users/xxx/.nvm/versions/node/v15.5.1/bin/node" "/Users/xxx/.nvm/versions/node/v15.5.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/xxx/Projects/zzz/node_modules/bcrypt
npm ERR! gyp ERR! node -v v15.5.1
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2021-01-08T18_09_40_256Z-debug.log

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 16

Most upvoted comments

I don’t know if this is related, but I managed to get into a similarly broken state. As it turns out, I think this is user error not an issue with the bcrypt package itself. I realised that I had managed to get both the npm and install packages listed in my dependencies. (An easy typo which I think npm should prevent but that’s another story.) Bumping npm from 7.5.2 to 7.5.4 (matching my currently installed version) and then running npm install fixed the issue. (Of course, the actual fix is to remove npm from my dependencies.) While in this case the mistake was me fat fingering a command, I wonder whether it’s possible to get your package-lock.json into a similarly “broken” state with a less obvious cause?

Error message
npm ERR! code 1
npm ERR! path /Users/hugo/Sources/dashboard/node_modules/bcrypt
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@14.15.5 | darwin | x64
npm ERR! gyp info find Python using Python version 3.9.1 found at "/usr/local/opt/python@3.9/bin/python3.9"
npm ERR! gyp info spawn /usr/local/opt/python@3.9/bin/python3.9
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/hugo/.volta/tools/image/npm/7.5.4/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/hugo/Sources/dashboard/node_modules/bcrypt/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/hugo/.volta/tools/image/npm/7.5.4/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/hugo/Library/Caches/node-gyp/14.15.5/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/hugo/Library/Caches/node-gyp/14.15.5',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/hugo/.volta/tools/image/npm/7.5.4/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/hugo/Library/Caches/node-gyp/14.15.5/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/hugo/Sources/dashboard/node_modules/bcrypt',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Users/hugo/.volta/tools/image/npm/7.5.4/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Darwin 20.3.0
npm ERR! gyp ERR! command "/Users/hugo/.volta/tools/image/node/14.15.5/bin/node" "/Users/hugo/.volta/tools/image/npm/7.5.4/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/hugo/Sources/dashboard/node_modules/bcrypt
npm ERR! gyp ERR! node -v v14.15.5
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

macOS 11.2.1 Node v14.15.5 npm 7.5.4

Regenerating package-lock helped. Here is the diff: image

I agree with you @hugo. All I did was a npm i some-other-package@latest (I was already on latest, but I was just double checking) and it changed my package-lock.json. That broke bcrypt when trying to install in Docker and showed the same error. I reverted my package-lock.json and it fixed the problem.