运行npm install时,回调多次调用

时间:2016-09-29 01:46:59

标签: node.js amazon-web-services npm elastic-beanstalk

使用ElasticBeanStalk将我的Node.JS应用程序部署到AWS时遇到了一些麻烦。

一旦部署开始,在运行npm install脚本(由AWS默认)时,我会收到以下奇怪的错误:

material-ui@0.15.4 node_modules/material-ui
  ├── simple-assign@0.1.0
  ├── react-addons-create-fragment@15.3.2
  ├── react-addons-transition-group@15.3.2
  ├── keycode@2.1.7
  ├── warning@3.0.0 (loose-envify@1.2.0)
  ├── inline-style-prefixer@2.0.4 (hyphenate-style-name@1.0.1, bowser@1.4.6)
  ├── lodash@4.16.2
  ├── react-event-listener@0.2.1 (fbjs@0.8.5)
  └── recompose@0.20.2 (symbol-observable@0.2.4, change-emitter@0.1.2, hoist-non-react-statics@1.2.0, fbjs@0.8.5)
  npm ERR! Linux 4.1.17-22.30.amzn1.x86_64
  npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64/bin/npm" "--production" "install"
  npm ERR! node v4.3.0
  npm ERR! npm  v2.14.12

  npm ERR! Callback called more than once.
  npm ERR!
  npm ERR! If you need help, you may report this error at:
  npm ERR!     <https://github.com/npm/npm/issues>

  npm ERR! Please include the following file with any support request:
  npm ERR!     /tmp/deployment/application/npm-debug.log

任何人都可以帮我调试这个问题吗?我已经花了太多时间试图了解正在发生的事情,但到目前为止没有结果。

谢谢!

4 个答案:

答案 0 :(得分:3)

显然某些AWS区域确实存在与npm的连接问题(在此issue中相关)并且我通过强制npm通过http而不是https来下载模块来解决它。

为此,我将.npmrc文件添加到项目的根目录中,其中包含以下内容:
registry=http://registry.npmjs.org/

感谢 @Jason Livesay 提示和 @danilojun ,以帮助我找到最佳解决方案!

答案 1 :(得分:3)

更新npm为我解决了

npm i -g npm

答案 2 :(得分:1)

请粘贴完整的日志。验证VM是否具有足够的网络和其他资源(免费/廉价的AWS内容受到限制)。升级到最新的Node / npm。当您在github isshes中搜索该错误时,请查看有关github npm repo问题的大量评论,例如https://github.com/npm/npm/issues/9418#issuecomment-170244027和其他问题。

答案 3 :(得分:1)

我为我正在处理的项目派生的另一个解决方案是检查node_modules文件夹中的源代码,然后禁用自动npm install继承到EB。这可以帮助具有严格依赖性的脆弱节点应用程序。

您需要将以下脚本添加到.ebextensions:

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh":
    mode: "000755"
    owner: root
    group: users
    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.
      #==============================================================================

      #set -xe
      #DO NOT RUN NPM...project contains node_modules
      #/opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install