Search code examples
node.jsexpressbcrypt

Bcrypt file too short


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.


Solution

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