【问题标题】:Heroku file not found in release phase but exists in the releaseHeroku 文件在发布阶段未找到,但在发布中存在
【发布时间】:2022-01-13 08:03:01
【问题描述】:

我有一个从 github 操作工作流部署到 ​​Heroku 的 Node 应用程序。我的 heroku procfile 包含一个运行迁移的发布阶段:

release: node packages/server/lib/entries/migrate.js
web: npm run start

Heroku 发布日志显示此错误,指出我的 migrate.js 文件丢失:

internal/modules/cjs/loader.js:818

  throw err;

  ^

Error: Cannot find module '/app/packages/server/lib/entries/migrate.js'

    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)

    at Function.Module._load (internal/modules/cjs/loader.js:667:27)

    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)

    at internal/main/run_main_module.js:17:47 {

  code: 'MODULE_NOT_FOUND',

  requireStack: []

}

但我可以确认该文件存在于 Heroku 中:

$ heroku run "ls -al /app/packages/server/lib/entries/migrate.js" --app my-app-name

-rw------- 1 u36913 dyno 3175 Jan  4 23:36 /app/packages/server/lib/entries/migrate.js

另外,我的应用是在部署到 Heroku 之前构建的,所以我在 Heroku 中禁用了构建:

"heroku-postbuild": "echo \"Skipping Heroku build.\"",

这是将应用程序部署到 Heroku 的 github 工作流程。我已确认工作流运行并执行 heroku 部署步骤(heroku 显示部署成功,但发布失败)。

name: Node.js CI

on:
  push:
    branches: [master, github_workflow_heroku_deploy]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '16'
      - run: npm ci
        env:
          NODE_ENV: development
      - run: npm run build
      - uses: akhileshns/heroku-deploy@v3.12.12
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/github_workflow_heroku_deploy' }}
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: 'my-heroku-app-name'
          heroku_email: 'my-heroku-email@example.com '

【问题讨论】:

    标签: node.js heroku github-actions


    【解决方案1】:

    问题最终是 akhileshns/heroku-deploy 操作使用 git 将项目部署到 Heroku,所以我编译的 lib 目录没有被创建。当我使用 heroku run bashheroku run ls 在 Heroku 中手动检查时,我不确定为什么存在 lib 文件夹。

    修复是在运行 heroku 部署操作之前强制添加并将构建提交到 github:

    - run: git config --global user.email "email@example.com" && git config --global user.name "ci" && git add . && git add --force packages/server/lib && git add --force packages/shared/lib && git add --force packages/client/build && git commit -am "Deploy Heroku Commit"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      相关资源
      最近更新 更多