Heroku构建失败的node.js

时间:2020-09-05 00:09:09

标签: mysql node.js heroku

我的开发版本运行正常,但我不明白为什么部署失败。 使用MySQL的ClearDB插件,但由于日志输出为“已连接”,因此我无法确定数据库连接是否是问题所在。

日志:

-----> Build
       Running heroku-postbuild
       
       > react-notes-app@0.1.0 heroku-postbuild /tmp/build_8b518789_
       > node api/server.js
       
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Connected!
-----> Timed out running buildpack Node.js
Terminated
 !     Push failed

db.js:

const mysql = require('mysql');

var con = mysql.createPool(db_config);

con.getConnection(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

//some functions

server.js:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const session = require('express-session');
const PORT = 5000 || process.env.port;
const cors = require('cors');
const path = require('path');
const db = require('./db.js');
var md5 = require('md5');


app.use(express.static(path.join(__dirname, '../build')));
app.use(cors());

app.get('/', function(req,res) {
  res.sendFile(path.join(__dirname, '../build', 'index.html'));
});

//other stuff

阅读类似文章的答案,其中一些在依赖性方面存在问题。

package.json:

{
  "name": "react-notes-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "cors": "^2.8.5",
    "express-session": "^1.17.1",
    "md5": "^2.3.0",
    "mysql": "^2.18.1",
    "node-fetch": "^2.6.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3"
  },
  "proxy" : "https://reactnote-app.herokuapp.com",
  "scripts": {
    "start": "react-scripts start",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "heroku-postbuild": "node api/server.js" 
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "engines":{
    "node":"v12.18.3",
    "npm":"6.14.6"
  }
}

0 个答案:

没有答案