【问题标题】:No Procfile and no package.json file found in Current Directory - See run-foreman.js在当前目录中找不到 Procfile 和 package.json 文件 - 请参阅 run-foreman.js
【发布时间】:2021-09-27 02:07:49
【问题描述】:

我正在尝试将 django 应用程序部署到 heroku,这导致我出错。运行命令时在调试过程中

heroku local web -f Procfile.windows

它显示以下错误:

[FAIL] No Procfile and no package.json file found in Current Directory - See run-foreman.js --help

从附件的应用结构中可以看到有Proc文件,Procfile的内容如下:

web: gunicorn klaviyo_integration.wsgi --log-file -

有没有猜到哪里出了问题?

我使用 Windows 作为操作系统,以防 gunicorn 在这个意义上出现问题。

【问题讨论】:

    标签: django heroku procfile


    【解决方案1】:

    我对 tmp 目录也有同样的问题。 我可以通过从 .gitignore 中删除来解决它。检查 .gitignore 中的 Procfile

    【讨论】:

    • 我检查了我的 .gitignore 文件,但没有 procfile。但是还有一些其他文件并删除了这些文件,导致我的本地 heroku 部署工作正常。感谢您的提示,我将对其进行投票,但由于本地尚未运行,因此无法将其标记为答案!
    【解决方案2】:

    这可能是由错误的 Procfile 语法引起的。

    尝试从您的 Procfile 中删除任何注释。它适用于我的情况。

    我原来的Procfile:

    # Some comment here
    
    web: python start.py --port %PORT%
    

    删除评论后,不再出现错误。

    web: python start.py --port %PORT%
    

    【讨论】:

      【解决方案3】:

      BLUF:尝试验证您的 Procfile 是否实际保存为 UTF-8 文件


      如何更好地调试您的问题:

      这是 Heroku-cli 在无法解析您的 Procfile 时返回的一般错误,不幸的是,它的日志记录并不能告诉您问题所在。

      对我来说,当我尝试在 Windows 上的 Pycharm 中创建 Procfile 时遇到了这个错误

      $ heroku local
      [WARN] Cannot read property '1' of null
      [FAIL] No Procfile and no package.json file found in Current Directory - See run --help
      TypeError: Cannot convert undefined or null to object
          at Function.keys (<anonymous>)
          at Index.run (/usr/local/lib/heroku/node_modules/@heroku-cli/plugin-local/lib/commands/local/index.js:30:38)
          at Index._run (/usr/local/lib/heroku/node_modules/@oclif/command/lib/command.js:44:31)
      

      事实证明,heroku 服务器提供了更好的错误消息!

      当我尝试将更改直接推送到 heroku 时,我找到了真正的根本原因:

      $ git push heroku main
      Counting objects: 102, done.
      Delta compression using up to 4 threads.
      Compressing objects: 100% (96/96), done.
      Writing objects: 100% (102/102), 33.93 KiB | 808.00 KiB/s, done.
      Total 102 (delta 31), reused 0 (delta 0)
      remote: Compressing source files... done.
      remote: Building source:
      git bremote:
      remote: -----> Building on the Heroku-20 stack
      remote: -----> Determining which buildpack to use for this app
      remote: -----> Python app detected
      remote: -----> Using Python version specified in runtime.txt
      remote: Traceback (most recent call last):
      remote:   File "/tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/vendor/runtime-fixer", line 8, in <module>
      remote:     r = f.read().strip()
      remote:   File "/usr/lib/python3.8/codecs.py", line 322, in decode
      remote:     (result, consumed) = self._buffer_decode(data, self.errors, final)
      remote: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
      remote: /tmp/codon/tmp/buildpacks/0f40890b54a617ec2334fac0439a123c6a0c1136/bin/steps/python: line 5: warning: command substitution: ignored null byte in input
      remote: ) is not available for this stack (heroku-20).
      remote:  !     Aborting.  More info: https://devcenter.heroku.com/articles/python-support
      remote:  !     Push rejected, failed to compile Python app.
      remote:
      rremote:  !     Push failed
      anremote: Verifying deploy...
      remote:
      remote: !       Push rejected to salty-ocean-58897.
      remote:
      To https://git.heroku.com/salty-ocean-58897.git
       ! [remote rejected] main -> main (pre-receive hook declined)
      error: failed to push some refs to 'https://git.heroku.com/salty-ocean-58897.git'
      

      具体来说,注意这一行:

      remote: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

      这让我找到了正确的方向,并让我意识到 Pycharm 已将我的 Procfile、runtime.txt 和 requirements.txt 文件创建为 utf-16 文件。将它们转换为 utf-8 修复了错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-05
        相关资源
        最近更新 更多