处理 node.js 私有模块依赖项的推荐方法是啥?

Posted

技术标签:

【中文标题】处理 node.js 私有模块依赖项的推荐方法是啥?【英文标题】:What is the recommended way to handle node.js private module dependencies?处理 node.js 私有模块依赖项的推荐方法是什么? 【发布时间】:2014-05-16 20:07:39 【问题描述】:

我目前正在开发一个部署在 Elastic Beanstalk 上的 node.js 应用程序。它已开始引用托管在 github 上的私有模块作为私有存储库。在本地,如果我在 package.json 的依赖项部分中引用它,如下所示,它可以正常工作。我可以运行 nom install,它会下载模块并且应用程序可以正常运行。

"ModuleName": "git+https://TOKEN:x-oauth-basic@github.com/OWNER/REPO_NAME.git"

但是,当我尝试部署到 Beanstalk 时,它失败并出现以下错误:

2014-04-04 00:14:09,188 [DEBUG] (1630 MainThread) [commandWrapper.py-60] [root commandWrapper main] Command result: 'status': 'FAILURE', 'results': ['status': 'FAILURE', 'config_sets': ['Infra-EmbeddedPreBuild', 'Hook-PreAppDeploy', 'Infra-EmbeddedPostBuild'], 'returncode': 1, 'events': ['msg': 'Failed to run npm install. Snapshot logs for more details.', 'timestamp': 1396570449, 'severity': 'ERROR', 'msg': 'Failed to run npm install. npm http GET https://registry.npmjs.org/express\nnpm ERR! not found: git\nnpm ERR! \nnpm ERR! Failed using git.\nnpm ERR! This is most likely not a problem with npm itself.\nnpm ERR! Please check if you have git installed and in your PATH.\n\nnpm ERR! System Linux 3.4.73-64.112.amzn1.x86_64\nnpm ERR! command "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.10.26-linux-x64/bin/npm" "install"\nnpm ERR! cwd /tmp/deployment/appli', 'timestamp': 1396570449, 'severity': 'ERROR'], 'msg': 'Error occurred during build: Command hooks failed\n'], 'api_version': '1.0'

据我所知,Beanstalk 使用的默认 linux AMI 上似乎没有安装 git。我的问题是处理这个问题的最佳方法是什么。目前我正在考虑以下两种选择:

    要么使用已安装 git 的 AMI,要么在引导期间以某种方式强制安装。 创建一个构建过程,在部署到 Beanstalk 之前打包我的所有 node_modules。

这两个选项有意义还是我应该考虑其他选项?有没有推荐的方法来使用 Elastic Beanstalk 或在一般的节点生态系统中处理这个问题?

【问题讨论】:

我会选择选项(2) 我不确定 Elastic Beanstalk 是否没有安装 git。我想问题是访问您的私人存储库的权限。尝试阅读此http://***.com/questions/13476138/setting-up-private-github-access-with-aws-elastic-beanstalk-and-ruby-container 【参考方案1】:

您可以通过在 .ebextensions 文件夹中添加配置文件来确保机器上安装了 git。见http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

如果您添加一个名为 .ebextensions/packages.config 的文件,其中包含以下内容:

#extra yum packages
packages:
  yum:
    git: []

这将在安装应用程序之前在机器上安装 git。

【讨论】:

以上是关于处理 node.js 私有模块依赖项的推荐方法是啥?的主要内容,如果未能解决你的问题,请参考以下文章

在 Lua 项目中管理开发依赖项的推荐方法是啥?

浏览器Javascript类(不是node.js)中私有方法的语法是啥? [复制]

浅析Node.js中使用依赖注入的相关问题及解决方法

通过 radius API 或 Node.js 模块在世界范围内搜索 zip 的好方法是啥?

在 Yarn 2 (berry) 中审计依赖项的最佳方法是啥?

具有依赖项的 CocoaPods 框架 - 在框架模块中包含非模块化标头