Heroku 部署失败,“错误代码=H10”:Vue.js + NodeJS 应用程序

时间:2021-04-27 15:55:36

标签: node.js vue.js heroku deployment

我正在尝试从同一个存储库将 Vue.js + NodeJS 应用程序部署到 Heroku,但我每次都收到“错误代码 = H10”。

经过几天的研究,我在这里分享了我为尝试修复此错误而修改的所有相关信息:

1.存储库结构:

client
 ↳ package.json
 ↳ dist
server
 ↳ bin
   ↳ www
 ↳ app.js
 ↳ package.json
Procfile
package.json

2.根 package.json

{
    "scripts": {
        "start": "cd server node ./bin/www && npm install",
        "heroku-postbuild": "cd client && npm install && npm run build"
    },
    "engines": {
        "node": "15.x",
        "npm": "6.x"
      }
}

3.个人资料

web: npm start

4.服务器包.json

  "scripts": {
    "dev": "./node_modules/.bin/vue-cli-service start",
    "start": "serve -s build",
    "serve": "./node_modules/.bin/vue-cli-service serve",
    "build": "./node_modules/.bin/vue-cli-service build",
    "lint": "./node_modules/.bin/vue-cli-service lint"
  }

5.客户端 package.json

  "scripts": {
    "start": "node ./bin/www",
    "dev": "nodemon ./bin/www"
  }

6. process.env.PORT(在 www 文件中)

const port = process.env.PORT || 5000;
app.set('port', port);

7. app.js

const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');

// OPTION 1:
app.use(express.static(path.join(__dirname, 'public')));

// OPTION 2:
var distDir = __dirname + "/dist/";
app.use(express.static(distDir));

// OPTION 3:
app.use('/', serveStatic(path.join(__dirname, '/dist')))
app.get(/.*/, function (req, res) {
    res.sendFile(path.join(__dirname, '/dist/index.html'))
})

8. Heroku 相关配置

heroku config:set USE_NPM_INSTALL=true
heroku config:set NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false

我还手动将 .env 文件中存储的所有变量添加到 Heroku 中的配置变量中。

请注意,“dist”文件夹是在从客户端文件夹运行“npm run build”后生成的,但我不确定这是否必要或足以准备部署。

欢迎提出任何意见。谢谢!

0 个答案:

没有答案
相关问题