1

Bcrypt with its dependency node-pre-gyp causes some serious issue when deployed to Elastic Beanstalk.

bcrypt version: 3.0.6

Nodejs version: 8.16 (also same for v.10)

Amazon Linux 4.8.2

bcrypt@3.0.6 install /tmp/deployment/application/node_modules/bcrypt
node-pre-gyp install --fallback-to-build

module.js:550
throw err;
^

Error: Cannot find module '../'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/tmp/deployment/application/node_modules/.bin/node-pre-gyp:15:20)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@3.0.6 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bcrypt@3.0.6 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! /tmp/.npm/_logs/2019-08-11T14_06_34_179Z-debug.log
Running npm install: /opt/elasticbeanstalk/node-install/node-v8.15.1-linux-x64/bin/npm
Setting npm config jobs to 1
npm config jobs set to 1
Running npm with --production flag
Failed to run npm install. Snapshot logs for more details.
UTC 2019/08/11 14:06:34 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log 

And relevant sections of package.json

"dependencies": {
    "axios": "^0.19.0",
    "bcrypt": "^3.0.6",
    "body-parser": "^1.18.3",
    "chai": "^4.2.0",
    "express": "^4.16.4",
    "firebase": "^5.8.6",
    "firebase-admin": "~6.0.0",
    "jsonwebtoken": "^8.5.0",
    "mocha": "^6.0.2",
    "shortid": "^2.2.14"
  },
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.3.4",
    "@babel/polyfill": "^7.2.5",
    "@babel/preset-env": "^7.3.4",
    "eslint": "^4.12.0",
    "eslint-plugin-promise": "^3.6.0"
  },
  "private": true
}
matcheek
  • 4,887
  • 9
  • 42
  • 73

1 Answers1

2

When deploying to Elastic Beanstalk running Node 8.x, node-gyp doesn't have sufficient permissions to write to the tmp directory. bcrypt won't install and the application deployment will fail.

A workaround is to add a .npmrc file to the root of your project that will force node-gyp to run as root and allow the installation to complete. File contents for .npmrc:

# Force npm to run node-gyp also as root, preventing permission denied errors in AWS with npm@5 or @6
unsafe-perm=true

pls check this also https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

Credit goes to this post: Beanstalk: Node.js deployment - node-gyp fails due to permission denied

Sandeep Patel
  • 4,815
  • 3
  • 21
  • 37