Heroku 为带有嵌套 react/webpack 客户端的节点服务器永远构建循环 github 回购

Heroku build loops forever for node server with nested react/webpack client on it's own github repo

我正在尝试 运行 heroku 上的服务器,该服务器的目录类似于

my-app
    server.js
    package.json
    client
        src
        dist
        package.json

嵌套的 package.json 有一个包含

scripts 部分

      "scripts": {
        "start": "webpack-dev-server --open --mode development",
        "build": "webpack --mode production"
      },

外部 package.json 有一个像这样的脚本部分

      "scripts": {
        "start": "node server",
        "build": "cd client/ && npm install && npm run build"
      },

当我将我的项目推送到 heroku 时,我收到了这个输出,它一直循环下去

     Build
    remote:        Running build
    remote:        
    remote:        > my-app@1.0.0 build /tmp/build_myapp
    remote:        > cd client/ && npm install && npm run build
    remote:
    remote:        audited 259 packages in 2.495s
    remote:        
    remote:        3 packages are looking for funding
    remote:          run `npm fund` for details
    remote:
    remote:        found 1 low severity vulnerability
    remote:          run `npm audit fix` to fix them, or `npm audit` for details
    remote:        
    remote:        > my-app@1.0.0 build /tmp/build_myapp
    remote:        > cd client/ && npm install && npm run build
    remote:
    remote:        audited 259 packages in 2.252s
    remote:        
    remote:        3 packages are looking for funding
    remote:          run `npm fund` for details
    remote:
    remote:        found 1 low severity vulnerability
    remote:          run `npm audit fix` to fix them, or `npm audit` for details
    remote:        
    remote:        > my-app@1.0.0 build /tmp/build_myapp
    remote:        > cd client/ && npm install && npm run build
    remote:
    remote:        audited 259 packages in 2.238s
    remote:        
    remote:        3 packages are looking for funding
    remote:          run `npm fund` for details


我在 github 存储库上有一个节点服务器。此回购协议中的文件夹之一是客户端文件夹,它有自己的 github 回购协议。我使用服务器文件夹中的 git push heroku master 将所有内容推送到 heroku。

很可能是因为构建命令一次又一次地 运行ning 自身,您可以通过将外部脚本的名称更改为构建以外的名称来解决此问题,比方说 buildClient

"scripts": {
    "start": "node server",
    "buildClient": "cd client/ && npm install && npm run build"
},

和 运行 npm run-script buildClient 而不是 npm build.

不确定您是否可以 运行 在 heroku 上自定义脚本,但您应该可以将脚本从 build 重命名为 heroku-postbuild,它应该可以工作。

我认为你应该像这样使用 Procfile。

web: npm run start

外面的package.json是这样的

"scripts": {
  "start": "node server",
  "heroku-postbuild": "cd client/ && npm install && npm run build"
},

如果这不起作用,请查看这篇文章。 如何使用 Heroku 在 monorepo 中部署多个应用程序
这篇文章提到了heroku上的多个app,应该会有帮助