如何在弹性 beanstalk 中安装 grunt?

How to install grunt in elastic beanstalk?

我正在尝试使用 beantalk 部署我的应用程序。我用 grunt dev 开始我的本地环境。错误提示找不到grunt。

使用 eb ssh 登录服务器后,我发现 npm 也没有安装。

我正在寻找解决此问题的后续步骤。

.ebextensions/01_grunt.config

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeCommand
    value: "grunt dev"

eb 日志

...
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
Wed, 04 Mar 2015 19:07:54 GMT express deprecated res.sendfile: Use res.sendFile instead at server.js:6:7
static file request : [object Object]
Wed, 04 Mar 2015 19:07:54 GMT express deprecated res.sendfile: Use res.sendFile instead at server.js:12:7
Error: ENOENT, stat '/var/app/current/libs/bootstrap-css/css/bootstrap.css'
static file request : [object Object]
static file request : [object Object]
Error: ENOENT, stat '/var/app/current/dist/libs.js'
Error: ENOENT, stat '/var/app/current/dist/app.js'
static file request : [object Object]
Error: ENOENT, stat '/var/app/current/favicon.ico'
static file request : [object Object]
Error: ENOENT, stat '/var/app/current/favicon.ico'
Listening on 8081

sh: grunt: command not found
sh: grunt: command not found
sh: grunt: command not found
sh: grunt: command not found
...

更新:

尝试过:.ebextensions/01_grunt.config(注意 npm install

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeCommand
    value: "npm install && grunt dev"

eb 日志

npm ERR! System Linux 3.14.27-25.47.amzn1.x86_64
npm ERR! command "/opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/bin/npm" "install" "&&" "grunt" "dev"
npm ERR! cwd /var/app/current
npm ERR! node -v v0.10.31
npm ERR! npm -v 1.4.23
npm ERR! Error: Attempt to unlock grunt, which hasn't been locked
npm ERR!     at unlock (/opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/lib/node_modules/npm/lib/utils/locker.js:44:11)
npm ERR!     at cb (/opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/lib/node_modules/npm/lib/cache/add-local.js:30:5)
npm ERR!     at /opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/lib/node_modules/npm/lib/cache/add-local.js:47:20
npm ERR!     at /opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/lib/node_modules/npm/lib/utils/locker.js:30:7
npm ERR!     at /opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
npm ERR!     at Object.oncomplete (fs.js:107:15)

没有理由让你的 BeanStalk 运行 grunt。这增加了一个不必要的故障点。

您应该交付已编译的资产并添加一个 npm start 脚本和正确的命令来启动您的应用程序。

例如,在您的 package.json:

{
  "name": "myApp",
  "version": "1.0.0",
  "scripts": {
    "start": "node myApp.js"
  }
}

如果你真的想要它,你可以添加grunt-cli作为依赖,并使用node_modules/grunt-cli/bin/grunt到运行中的bin它。但是,请:不要!