Heroku Procfile - 运行npm start

时间:2015-06-22 23:54:43

标签: node.js heroku npm

的package.json

{
  //Other stuff here

  "scripts": {
    "prestart": "./scripts/prestart.sh",
    "start": "./scripts/start.sh"
  }
}

prestart.sh

#!/usr/bin/env bash
set -ex
webpack

start.sh

#!/usr/bin/env bash
set -ex
http-server -p $PORT

Procfile

web: npm start

当我推送到heroku时,我收到应用程序错误。所以我运行了一个heroku run bash,并注意到prestart和start脚本根本没有运行(运行prestart调用webpack - 这将创建一个带有js文件的生成文件夹)。

有什么想法可以解决这个问题吗?

编辑:

  1. 当我把它放在postinstall中而不是prestart时,Webpack现在可以正常工作。

  2. http-server不运行。当我运行heroku logs --tail时,我看不到http-server的任何输出。

  3. heroku logs --tail

    的输出
    2015-06-23T18:05:55.628044+00:00 heroku[slug-compiler]: Slug compilation started
    2015-06-23T18:05:55.628049+00:00 heroku[slug-compiler]: Slug compilation finished
    2015-06-23T18:05:55.582057+00:00 heroku[api]: Deploy ** by ***
    2015-06-23T18:05:55.582057+00:00 heroku[api]: Release v14 created by ****
    2015-06-23T18:07:49.114534+00:00 heroku[api]: Starting process with command `bash` by ****
    2015-06-23T18:07:54.748361+00:00 heroku[run.8851]: Starting process with command `bash`
    2015-06-23T18:07:54.701235+00:00 heroku[run.8851]: Awaiting client
    2015-06-23T18:07:54.808283+00:00 heroku[run.8851]: State changed from starting to up
    2015-06-23T18:22:20.007391+00:00 heroku[run.8851]: State changed from up to complete
    2015-06-23T18:22:19.997342+00:00 heroku[run.8851]: Process exited with status 0
    

1 个答案:

答案 0 :(得分:3)

如果您使用webpack构建应用,则应将其放入postinstall脚本(而不是prestart),以便在构建时运行。

当Heroku尝试启动您的应用时,

npm start应该定期执行。要查看正在发生的情况,请查看heroku logs --tail