【问题标题】:Heroku web: Failed at start scriptHeroku web:启动脚本失败
【发布时间】:2019-09-02 04:32:01
【问题描述】:

我收到了

sequelize-demo@1.0.0 启动脚本失败。

在部署 express + react 应用程序时。我认为 heroku 遇到了concurrently 的问题。

我可能做错了什么?我引用了this,但解决方案与此应用程序有点无关

也引用了这个

https://medium.freecodecamp.org/how-to-deploy-a-react-app-with-an-express-server-on-heroku-32244fe5a250

根文件夹 package.json

{
  "name": "sequelize-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "build": "concurrently \"cd client && npm run build\" \"npm build \"",
    "test": "echo \"Error: no test specified\" && exit 1",
    "client": "cd ./client && npm start ",
    "server-prod": "node app.js",
    "server": "nodemon app.js",
    "start": "concurrently --kill-others  \"npm run client\" \"npm run server\" ",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async": "^2.6.1",
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "concurrently": "^4.1.0",
    "cookie-parser": "^1.4.3",
    "cookie-session": "^2.0.0-beta.3",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "dotenv": "^7.0.0",
    "express": "^4.16.4",
    "express-flash": "0.0.2",
    "express-session": "^1.15.6",
    "foreman": "^3.0.1",
    "jsonwebtoken": "^8.4.0",
    "morgan": "^1.9.1",
    "nodemailer": "^5.1.1",
    "nodemon": "^1.18.9",
    "passport": "^0.4.0",
    "passport-github": "^1.1.0",
    "passport-github2": "^0.1.11",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "pg": "7.9.0",
    "pg-hstore": "^2.3.2",
    "sequelize": "^4.42.0",
    "sequelize-cli": "^5.4.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^6.1.2"
  }
}

client/package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:8000",
  "dependencies": {
    "@material-ui/core": "^3.9.1",
    "@material-ui/icons": "^3.0.2",
    "axios": "^0.18.0",
    "history": "^4.7.2",
    "http-proxy-middleware": "^0.19.1",
    "jsonwebtoken": "^8.4.0",
    "jwt-decode": "^2.2.0",
    "material-ui-icons": "^1.0.0-beta.36",
    "moment": "^2.24.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-redux": "^6.0.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.3",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "superagent": "^4.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "heroku-postbuild": "npm run build"
  },
  
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "dotenv": "^6.2.0"
  }
}

个人资料

web: npm run start

日志

用户数据库和用户表已创建

状态从开始变为向上

某些东西已经在端口 32000 上运行。

npm run 客户端退出,代码为 0

向其他进程发送 SIGTERM..

npm 运行服务器退出,代码 SIGTERM `

npm 错误! sequelize-demo@1.0.0 开始:concurrently --kill-others "npm run client" "npm run server"

npm 错误!退出状态 1 2019-04-11T07:26:41.326088+00:00 app[web.1]:

npm 错误! 2019-04-11T07:26:41.326282+00:00 应用[web.1]:

npm 错误! sequelize-demo@1.0.0 启动脚本失败。

【问题讨论】:

  • 你不能在 heroku 上同时运行 2 个服务器,必须为后端创建另一个应用程序。
  • 我认为,当你在 heroku 上部署时,你应该将你的 react 文件从 node.js 构建到 bundle 和 server 中作为公共资产
  • 什么是好的堆栈溢出问题或任何其他要查看的资源?所以你的意思是部署到heroku时并发不会工作?
  • 他们是后端,请检查 repo。 github.com/EliHood/mysequelizereact,让我知道您将如何更改它以使其适合部署
  • 客户端为前端,服务端在app.js上

标签: node.js reactjs express heroku


【解决方案1】:

修复它,我没有反应构建。

我从中学到了什么

https://medium.freecodecamp.org/how-to-deploy-a-react-app-with-an-express-server-on-heroku-32244fe5a250

现在我们需要确保在将项目推送到 Heroku 存储库之前,我们的项目中有一个 build 文件夹。将以下脚本添加到您的 package.json 文件中 - 博客作者

所以我在客户端目录上做了一个 npm run build。

然后将我的 package.json 更改为

{
  "name": "sequelize-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "build": "concurrently \"cd client && npm run build\" \"npm build \"",
    "test": "echo \"Error: no test specified\" && exit 1",
    "client": "cd ./client && npm start ",
    "server-prod": "node app.js",
    "server": "nodemon app.js",
    "start": "node app.js",
    "start:dev": "concurrently --kill-others  \"npm run client\" \"npm run server\" ",
    "heroku-postbuild":"NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async": "^2.6.1",
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "concurrently": "^4.1.0",
    "cookie-parser": "^1.4.3",
    "cookie-session": "^2.0.0-beta.3",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "dotenv": "^7.0.0",
    "express": "^4.16.4",
    "express-flash": "0.0.2",
    "express-session": "^1.15.6",
    "foreman": "^3.0.1",
    "jsonwebtoken": "^8.4.0",
    "morgan": "^1.9.1",
    "nodemailer": "^5.1.1",
    "nodemon": "^1.18.9",
    "passport": "^0.4.0",
    "passport-github": "^1.1.0",
    "passport-github2": "^0.1.11",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "pg": "7.9.0",
    "pg-hstore": "^2.3.2",
    "sequelize": "^4.42.0",
    "sequelize-cli": "^5.4.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^6.1.2"
  }
}

将此添加到 app.js

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

if(process.env.NODE_ENV === 'production') {
  app.use(express.static(path.join(__dirname, 'client/build')));
  //
  app.get('*', (req, res) => {
    res.sendfile(path.join(__dirname = 'client/build/index.html'));
  })
}
//build mode
app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname+'/client/public/index.html'));
})

个人资料

web: npm start

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 2018-04-29
    • 2019-06-07
    • 1970-01-01
    • 2019-07-10
    • 2019-07-17
    • 2017-06-07
    • 2018-05-09
    • 2013-02-06
    相关资源
    最近更新 更多