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 修复了错误。