Heroku с React и сборкой нодмейлера не работает - PullRequest
0 голосов
/ 13 июня 2018

У меня проблемы с получением моей сборки на героку на работу.Heroku говорит, что сборка прошла успешно, но когда я открываю страницу, появляется страница «Ошибка приложения».

Вот мой пакет. JSON для React

{
  "name": "cloudveilheli",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:3001",
  "dependencies": {
    "axios": "^0.18.0",
    "body-parser": "^1.18.3",
    "concurrently": "^3.5.1",
    "express": "^4.16.3",
    "firebase": "^4.8.1",
    "moment": "^2.22.1",
    "nodemailer": "^4.6.5",
    "nodemon": "^1.17.5",
    "re-base": "^3.2.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2"
  },
  "devDependencies": {
    "node-sass": "^4.7.2",
    "react-scripts": "1.0.17",
    "redux": "^3.7.2",
    "sass-loader": "^6.0.6",
    "webpack": "^3.10.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

и для node.js

{
  "name": "cloudveilheli",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:3001",
  "dependencies": {
    "axios": "^0.18.0",
    "body-parser": "^1.18.3",
    "concurrently": "^3.5.1",
    "express": "^4.16.3",
    "firebase": "^4.8.1",
    "moment": "^2.22.1",
    "nodemailer": "^4.6.5",
    "nodemon": "^1.17.5",
    "re-base": "^3.2.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2"
  },
  "devDependencies": {
    "node-sass": "^4.7.2",
    "react-scripts": "1.0.17",
    "redux": "^3.7.2",
    "sass-loader": "^6.0.6",
    "webpack": "^3.10.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

В журналах я получаю сообщение об ошибке-скрипты терпят неудачу в процессе сборки Heroku.Узел и реакция запускаются, но вскоре после этого происходит сбой.

А вот логи герои

2018-06-13T12:56:17.879178+00:00 app[web.1]: [1] sh: 1: react-scripts: not found
2018-06-13T12:56:17.910185+00:00 app[web.1]: [1] npm ERR! file sh
2018-06-13T12:56:17.910189+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.912160+00:00 app[web.1]: [1] npm ERR! errno ENOENT
2018-06-13T12:56:17.913985+00:00 app[web.1]: [1] npm ERR! syscall spawn
2018-06-13T12:56:17.922554+00:00 app[web.1]: [1] npm ERR! cloudveilheli@0.1.0 start: `react-scripts start`
2018-06-13T12:56:17.927487+00:00 app[web.1]: [1] npm ERR! spawn ENOENT
2018-06-13T12:56:17.928818+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:17.932398+00:00 app[web.1]: [1] npm ERR! Failed at the cloudveilheli@0.1.0 start script.
2018-06-13T12:56:17.932401+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:17.967183+00:00 app[web.1]: [1] npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2018-06-13T12:56:17.968219+00:00 app[web.1]: [1]
2018-06-13T12:56:17.968222+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:17.968224+00:00 app[web.1]: [1] npm ERR!     /app/.npm/_logs/2018-06-13T12_56_17_935Z-debug.log
2018-06-13T12:56:17.992492+00:00 app[web.1]: [1] npm ERR! code ELIFECYCLE
2018-06-13T12:56:17.992495+00:00 app[web.1]: [1] npm ERR! errno 1
2018-06-13T12:56:17.996672+00:00 app[web.1]: [1] npm ERR! bluebirdheliapp@1.0.0 client: `npm run start --prefix cloudveil_heli_app`
2018-06-13T12:56:17.999397+00:00 app[web.1]: [1] npm ERR! Exit status 1
2018-06-13T12:56:18.004427+00:00 app[web.1]: [1] npm ERR!
2018-06-13T12:56:18.004430+00:00 app[web.1]: [1] npm ERR! Failed at the bluebirdheliapp@1.0.0 client script.
2018-06-13T12:56:18.004432+00:00 app[web.1]: [1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-06-13T12:56:18.021046+00:00 app[web.1]: [1]
2018-06-13T12:56:18.021050+00:00 app[web.1]: [1] npm ERR! A complete log of this run can be found in:
2018-06-13T12:56:18.021052+00:00 app[web.1]: [1] npm ERR!     /app/.npm/_logs/2018-06-13T12_56_18_005Z-debug.log
2018-06-13T12:56:18.046560+00:00 app[web.1]: [1] npm run client exited with code 1

1 Ответ

0 голосов
/ 13 июня 2018

пока вы толкаете ваше приложение к heroku

сначала оно запускается npm install

позже оно запускается npm start

поэтому мы должны объявить в package.json, что запускать после завершения установки npm и что нужно сделать при запуске npm.

обновить ваш package.json с помощью:

    {
      "name": "cloudveilheli",
      "version": "0.1.0",
      "private": true,
      "proxy": "http://localhost:3001",
"scripts": {
    "start": "node server.js",
    "postinstall": "npm start build "
  },
      "dependencies": {
        "axios": "^0.18.0",
        "body-parser": "^1.18.3",

, где postinstall работает после завершения npminstall и создает файл server.js следующим образом:

const express = require('express');
const app = express();

app.use(express.static(__dirname + '/dist'));

app.all('*', (req, res) => {
  res.status(200).sendFile(__dirname + '/dist/index.html');
});

app.listen(process.env.PORT || 8080);

в dist / index.html указывает, где index.html, созданный в реакции

как я не знаю, реагируют

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...