AWS - 通过npm install安装bower组件

8
我正在尝试使用git aws.push方法启动一个node.js服务器。

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.sdlc.html

与这个解决方案相似,我正在尝试运行“bower install”,但我的解决方案略有不同:

https://developer.ibm.com/answers/questions/16594/how-to-install-packages-on-nodejs/

我的实现:

"scripts": { "postinstall": "bower install -F" },

这在本地运行良好 - npm install也可以顺利运行bower install。当我部署到AWS时,npm也可以正常运行 - 我知道我的服务器启动良好,因为我可以在日志中看到来自它的消息,但是当我尝试启动客户端时,没有任何bower组件。

我正在使用node v0.10.26,并确信我没有在本地机器上全局安装bower。我已经尝试过包括和不包括bower在package.json的dependencies部分。

有什么想法吗?提前感谢。

package.json

{
  "name": "smf",
  "version": "0.1.0",
  "dependencies": {
    "aws-sdk": "~2.0.0-rc.14",
    "base64-js": "0.0.6",
    "bookshelf": "~0.6.10",
    "bower": "*",
    "change-case": "~2.1.1",
    "crypto-js": "~3.1.2-3",
    "geojson": "~0.1.5",
    "handlebars": "~2.0.0-alpha.2",
    "js-base64": "~2.1.5",
    "lodash": "~2.4.1",
    "mathjs": "~0.21.0",
    "minify": "~0.5.1",
    "moment": "~2.6.0",
    "newrelic": "~1.5.3",
    "node-cryptojs-aes": "~0.4.0",
    "node-highcharts": "0.0.2",
    "node-uuid": "~1.4.1",
    "passport": "~0.2.0",
    "passport-http": "~0.2.2",
    "passport-local": "~1.0.0",
    "password-hash": "~1.2.2",
    "pg": "~3.0.3",
    "restify": "~2.7.0",
    "should": "~3.3.1",
    "socket.io": "~0.9.16",
    "sqlite3": "~2.2.3",
    "util": "~0.10.3",
    "when": "~3.1.0"
  },
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-jshint": "^0.10.0",
    "grunt-mocha-test": "~0.9.0",
    "mocha-phantomjs": "~3.3.1"
  },
  "scripts": {
    "postinstall": "bower install -F"
  },
  "engines": {
    "node": ">=0.6"
  }
}

日志文件

整个日志太长了,如果需要,我可以将其分成多个评论粘贴。以下是唯一提到bower的部分。

如果我尝试访问网站,我可以获得访问日志,指示缺少bower组件。

似乎没有执行bower install。


/var/log/directory-hooks-executor.log


underscore.string@2.3.3 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string esprima@1.0.4 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/node_modules/esprima object-assign@0.3.1 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/configstore/node_modules/object-assign uuid@1.4.1 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/configstore/node_modules/uuid latest-version@0.2.0 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version package-json@0.2.0 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json got@0.3.0 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/got object-assign@0.3.1 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/got/node_modules/object-assign registry-url@0.1.1 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url npmconf@2.0.2 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf config-chain@1.1.8 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/config-chain proto-list@1.2.3 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/config-chain/node_modules/proto-list ini@1.2.1 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/ini inherits@2.0.1 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/inherits mkdirp@0.3.5 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/mkdirp once@1.3.0 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/once uid-number@0.0.5 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url/node_modules/npmconf/node_modules/uid-number semver-diff@0.1.0 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/semver-diff string-length@0.1.2 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/string-length strip-ansi@0.2.2 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/string-length/node_modules/strip-ansi ansi-regex@0.1.0 /tmp/deployment/application/node_modules/bower/node_modules/update-notifier/node_modules/string-length/node_modules/strip-ansi/node_modules/ansi-regex which@1.0.5 /tmp/deployment/application/node_modules/bower/node_modules/which


你可以尝试按照这里的说明对日志进行快照:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.loggingS3.title.html吗? 同时,你能否发布package.json的确切内容。你问题中的内容当前显示在行末有一个逗号"scripts": { "postinstall": "bower install -F" },,这可能会引起问题。只是想确认这是否是一个打字错误。 - Rohit Banga
我已经添加了这些信息 - 但实际上并没有新的信息... - user2726306
这里有同样类型的问题... - AsTeR
3个回答

6
bower 可能未全局安装(如果已安装,请告诉我如何在 Elastic Beanstalk 上进行设置 :D)。 相反,您应该指向 node_modules 文件夹中的 bower 二进制文件(这就是我们以前所做的方式)。我们已经放弃了这种解决方案(考虑一下要扩展到 500 个实例),并将 bower_components 检入存储库。
"scripts": {
  "postinstall": "node_modules/bower/bin/bower install -F"
},

这对我来说根本无法运行。Bower包从未出现,我收到了404错误。 - BKH
还没有。我还在调查中。我尝试将bower install作为container_commands脚本运行,但是它也会出错,因为node没有链接到PATH环境变量中。https://dev59.com/bWMl5IYBdhLWcg3wr4nn#19011144展示了如何解决这个问题,但是git也需要链接。我不确定为什么Amazon不会直接运行postinstall。它应该在npm install运行时运行。 - BKH
我也尝试过使用 "postinstall": "node ./node_modules/bower/bin/bower install -F" 进行测试,但没有成功 :( - user1791139
"postinstall": "/opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/bin/node ./node_modules/bower/bin/bower install -F" 也不起作用... :( - user1791139
"postinstall" 对我来说运行良好...我在 .bowerrc 中给出了另一个路径 { "directory":"client/bower_components" } @BKH 这可能对你有帮助。创建 .bowerrc 文件并添加所需的目录路径。 - Gitaram Kanawade

3
将 .config 文件添加到您的 .ebextensions 目录以安装 bower 组件是有帮助的。不幸的是,默认情况下不会将 node 和 npm 添加到路径中,因此您需要找到最新的 node 实例并创建符号链接。我真的不喜欢将 bower 组件安装为 root,但这样可以解决问题:
commands:
  01_get_sudo:
      command: echo Defaults:root \!requiretty >> /etc/sudoers
  02_node_path:
    command: "sudo ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /usr/bin/node"
  03_npm_path:
    command: "sudo ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /usr/bin/npm"

container_commands:
  01_bower_install:
    command: "sudo ./node_modules/bower/bin/bower install --allow-root"

0

使用$NODE_HOME,例如:

container_commands:
  01_bower_install:
    command: "export PATH=$PATH; $NODE_HOME/bin/node ./node_modules/bower/bin/bower install --allow-root &>> /tmp/01_bower_install.log"

head -1 不一定会使用最新版本的 nodenpm

例如...

$ ls -td /opt/elasticbeanstalk/node-install/node-* | head -1
/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64

然而,ls 显示 v5.6.0 实际上是最新版本:

$ ls -td /opt/elasticbeanstalk/node-install/node-*
/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64
/opt/elasticbeanstalk/node-install/node-v0.10.42-linux-x64
/opt/elasticbeanstalk/node-install/node-v5.6.0-linux-x64
/opt/elasticbeanstalk/node-install/node-v0.8.28-linux-x64
/opt/elasticbeanstalk/node-install/node-v0.12.10-linux-x64

即使它这样做了,也可能不是你想要的。

您可以通过排序来解决此问题,但您仍然可能希望使用与环境相同的节点版本,该版本可以通过$NODE_HOME访问。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接