0

I am facing an error that causes a crush on my nodejs application. The error is below: '

Error: /home/*******/nodevenv/******/12/lib/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: file too short
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/outdoor1/nodevenv/prescription_server/12/lib/node_modules/bcrypt/bcrypt.js:6:16)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
internal/modules/cjs/loader.js:1057
return process.dlopen(module, path.toNamespacedPath(filename));

The application is hosted on CPanel-based shared hosting. The application is running for 6 months without error. But for 2 days the application is not running. I re-installed bcrypt. But nothing changes. The application working fine on my local pc.

1 Answers1

0

It looks as if your bcrypt binary has somehow become corrupted.

What was the result of your attempt to reinstall bcrypt? Where there any errors?

The bcrypt repo at https://github.com/kelektiv/node.bcrypt.js notes that it only works on "stable" releases of NodeJS greater than >= 10.0.0 and more importantly, requires recompilation on the host platform on install. If your host does not have a full build environment installed, you will not be able to compile this module locally.

Assuming you are running the correct version of NodeJS, you could try retrieving the repo directly to your host machine, cd to its directory, and run npm install to install its requirements. Chief among these is the node-pre-gyp which is a helper to ease the compilation of native node modules.

Once you've done this, you should be able to run the install command for bcrypt itself, as described in the repo's package.json file: node-pre-gyp install --fallback-to-build. (Note that, depending on how your host is configured, you might need to add npx to the beginning of that command to properly invoke node-pre-gyp, e.g. npx node-pre-gyp install --fallback-to-build)

Note any errors this throws and share them here as an update to your question. I'm guessing that the install fails during compilation and you missed the error messages involved.

Baring everything else, I'd also ask CPanel support since I am sure this is not a unique problem.

Rob Raisch
  • 17,040
  • 4
  • 48
  • 58
  • try using this library https://www.npmjs.com/package/bcrypt-inzi – Inzamam Malik Jun 26 '21 at 10:52
  • `bcrypt-inzi` requires `bcrypt-nodejs` which is deprecated. so, not recommended. – Rob Raisch Jun 29 '21 at 19:32
  • well said but as you can see in the last one year `bcrypt-nodejs` have constant ~70 thousand downloads every month, I found it very stable library and very light weight – Inzamam Malik Jun 29 '21 at 23:29
  • Yes, `bcrypt-nodejs` is stable. But, since it's deprecated, we cannot expect updates (including security patches) which is an important consideration. The biggest problem for the OP is that, since the app needs to run on a shared hosting solution, it's probably not feasible to require a module, like bcrypt, that has to be compiled on install for a specific host platform. – Rob Raisch Jul 02 '21 at 18:41
  • `bcrypt-inzi` Library is written by me and it is not deprecated yet I’m handling the issues, suggestions and patches, it is dependent on Bcrypt which is written is JavaScript, it is self sufficient and it runs evenly on all platforms such as linux windows and Mac systems, it doesn’t require nodegyp or c++ build tools like other bcrypt implementations, and this is the reason it is easily get installed, and I will make sure it continues doing that, I’m using it in lots of projects sofar no problem reported – Inzamam Malik Jul 04 '21 at 03:31
  • Just to make my point crystal clear, when you install `bcrypt-inzi` your project will always look for ^x.xx.x version of `bcrypt-inzi`, your project will not look for `bcrypt-nodejs` and for example if I change the behind-the-implementation of the library later(I’m not planning that yet but I have that option as last resort) it will change everywhere so it all depends on me not on that dependant library – Inzamam Malik Jul 04 '21 at 03:36
  • I contacted my server provider and asked them to rebuild the package. After rebuild the library worked. – Takiuddin Ahmed Jul 08 '21 at 20:15