node-gyp: AWS Elastic Beanstalk Build Error: node-gyp requires that the user home directory is specified in either of the environmental variables HOME or USERPROFILE

I have aws elastic beanstalk for node js application and I uploaded my node js app (zip file) to my instance but I saw this error in aws logs

The Error

node-gyp requires that the 'user'\''s' home directory is specified in either of the environmental variables HOME or 'USERPROFILE\n' at new Gyp '(/opt/elasticbeanstalk/node-install/node-v0.8.26-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:54:11

Package.json

{
  "name": "testing-beanstalk",
  "description": "Testing Beanstalk",
  "author": "Bugan",
  "version": "1.0",
  "private": true,  
  "dependencies": {
    "express": "3.x",
    "socket.io": "0.9.6",
    "mysql": "2.0.1",
    "cron": "1.0.0",
  }
}

Any idea to solve this problem? How to set user home directory?

Thank you before

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 1
  • Comments: 25 (1 by maintainers)

Most upvoted comments

This is not a valid fix. The module should be able to be installed without needing bash variables set.

The NPM package should be installable without any shell variables set. Please fix this. Nothing should be installed assuming a HOME directory or need a home directory value set. Nothing should be writing to the user home directory if I’m installing NPM packages globally.

this is still an issue; deploying to aws elastic beanstalk, and running into this same issue. Also have issues with it on windows, docker, and on it goes. It literally has to be the largest point of failure in the node world. fix it for christ sakes

Also, running Chef through CloudFormation using the nodejs_npm resource of the nodejs cookbook (https://github.com/redguide/nodejs) there is no opportunity to set bash variables.

Fix this properly - $HOME should NOT be required to install ANY software.

We ended up using a slightly modified version for our problem. Leaving it here for anyone else who may need it (bcrypt specific):

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: root
    content: |
      #!/bin/bash
      #==============================================================================
      # Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
      #
      # Licensed under the Amazon Software License (the "License"). You may not use
      # this file except in compliance with the License. A copy of the License is
      # located at
      #
      #       http://aws.amazon.com/asl/
      #
      # or in the "license" file accompanying this file. This file is distributed on
      # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or
      # implied. See the License for the specific language governing permissions
      # and limitations under the License.
      #==============================================================================

      export HOME=/home/ec2-user
      export USERPROFILE=/home/ec2-user

      sudo rm -rf /tmp/deployment/application/node_modules/bcrypt

      set -xe

      /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install


With eb you can define environment variables - is the question more about what directory to set it to?

Hello,

Sorry I have the same issue , I have tried your solutions but nothing works…

I have tried deerawan’s config I have tried rhyeal’s config

Do you have other solutions ?

node version: 4.4.3 os: 64bit Amazon Linux 2016.03 v2.1.1 running Node.js

Thanks !

Finally I solved it, there is no node-gyp error related anymore. The solution is I set HOME variable in the script below. This script will be executed in EB. 😃

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh" :
    mode: "000775"
    owner: root
    group: root
    content: |
      #!/bin/bash          
      function error_exit
      {
        eventHelper.py --msg "$1" --severity ERROR
        exit $2
      }

      export HOME=/home/ec2-user
      echo "export home"

      OUT=$(/opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install 2>&1) || error_exit "Failed to run npm install.  $OUT" $?
      echo $OUT

it can be closed now. Thank you

Don’t forget to have an .ebignore file. The .ebignore file should (generally) just be:

node_modules/

This was my error - I was on a wild goose chase for hours.

FWIW, I deployed a Node app to EB based on Amazon Linux 2015.03 today and this problem is no longer present. I poked around a bit and /opt/elasticbeanstalk/containerfiles/ebnode.py (which is used to drive the npm install) now sets $HOME.

(I’m not a fan of build tools depending on a homedir, but it does now seem to work.)