1

我创建了 Rails API 后端应用程序,并在文件夹客户端的应用程序内为我的前端创建了 create-react-app。它在我的本地机器上运行良好,但在 heroku 上运行时出现错误:

npm: command not found

这是应用程序的结构:

rails-app
  - app
     - controller
     - model
     - ...
  - client
     - package.json
     - index.jsx
     - ...
  - config
  - db
  - ...
  - Procfile

在 Procfile 我有:

web: cd client && npm start
api: bundle exec rails s -p 3001

在 package.json 里面:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:3001/",
  "devDependencies": {
    "react-scripts": "0.6.1"
  },
  "dependencies": {
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.14.0",
    "babel-preset-react": "^6.11.1",
    "firebase": "^3.4.1",
    "jquery": "^3.1.1",
    "react": "^15.3.2",
    "react-dom": "^15.3.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

(注意与我的 Rails 后端通信的代理)

赫罗库: 在此处输入图像描述

Heroku 日志:

2016-09-29T15:12:31.193617+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=strv-address-book.herokuapp.com request_id=bc33286a-3dd3-475f-b974-a00c5aee42f7 fwd="151.227.204.173" dyno= connect= service= status=503 bytes=
2016-09-29T15:12:44.403333+00:00 heroku[api.1]: Restarting
2016-09-29T15:12:44.404060+00:00 heroku[api.1]: State changed from up to starting
2016-09-29T15:12:45.064536+00:00 heroku[web.1]: State changed from crashed to starting
2016-09-29T15:12:47.345132+00:00 heroku[api.1]: Starting process with command `bundle exec rails s -p 3001`
2016-09-29T15:12:47.459080+00:00 heroku[web.1]: Starting process with command `cd client && npm start`
2016-09-29T15:12:47.931743+00:00 heroku[api.1]: State changed from starting to up
2016-09-29T15:12:48.531931+00:00 heroku[api.1]: Stopping all processes with SIGTERM
2016-09-29T15:12:49.283096+00:00 heroku[web.1]: State changed from starting to crashed
2016-09-29T15:12:49.263399+00:00 heroku[web.1]: Process exited with status 127
2016-09-29T15:12:49.036142+00:00 app[web.1]: bash: npm: command not found
2016-09-29T15:12:49.352458+00:00 app[api.1]: - Gracefully stopping, waiting for requests to finish
2016-09-29T15:12:49.352608+00:00 app[api.1]: === puma shutdown: 2016-09-29 15:12:49 +0000 ===
2016-09-29T15:12:49.352645+00:00 app[api.1]: - Goodbye!
2016-09-29T15:12:49.352737+00:00 app[api.1]: Exiting
2016-09-29T15:12:49.480691+00:00 heroku[api.1]: Process exited with status 0
2016-09-29T15:12:50.284874+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=strv-address-book.herokuapp.com request_id=c262f174-97c8-4326-a20b-3f13f2f6e99b fwd="151.227.204.173" dyno= connect= service= status=503 bytes=
2016-09-29T15:12:50.976612+00:00 app[api.1]: => Rails 5.0.0.1 application starting in production on http://0.0.0.0:3001
2016-09-29T15:12:50.976587+00:00 app[api.1]: => Booting Puma
2016-09-29T15:12:50.976617+00:00 app[api.1]: => Run `rails server -h` for more startup options
2016-09-29T15:12:51.938112+00:00 app[api.1]: Puma starting in single mode...
2016-09-29T15:12:51.938132+00:00 app[api.1]: * Version 3.6.0 (ruby 2.3.0-p0), codename: Sleepy Sunday Serenity
2016-09-29T15:12:51.938133+00:00 app[api.1]: * Min threads: 5, max threads: 5
2016-09-29T15:12:51.938134+00:00 app[api.1]: * Environment: production
2016-09-29T15:12:51.938225+00:00 app[api.1]: * Listening on tcp://0.0.0.0:3001
2016-09-29T15:12:51.938543+00:00 app[api.1]: Use Ctrl-C to stop
2016-09-29T15:12:52.380906+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=strv-address-book.herokuapp.com request_id=5d5f2cbb-4fd0-40f2-a8d4-86c2b8cf14f3 fwd="151.227.204.173" dyno= connect= service= status=503 bytes=

(我能够运行 heroku run rails c 没有任何错误)

如何告诉heroku有关反应应用程序或如何使其工作?

4

1 回答 1

0

似乎问题在于您的 Heroku 环境不知道如何运行npm,这是可以理解的,因为默认情况下 Heroku 会推断出要用于您的应用程序的buildpack 。

你可以按照这个添加 heroku-node buildpack 。

让我知道这是否有帮助,或者您是否需要进一步说明

于 2016-09-29T15:30:46.523 回答