【问题标题】:error: failed to push some refs to 'https://git.heroku.com/readingcom.git'错误:未能将一些参考资料推送到“https://git.heroku.com/readingcom.git”
【发布时间】:2020-10-17 02:58:13
【问题描述】:

! [remote rejected] master -> master (pre-receive hook declined)

我一直在尝试从 git repo oh heroku 部署这个应用程序,但是 pre-receive hook denied 错误不断弹出

在此处输入代码

remote: sh: 1: react-scripts: Permission denied
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! client@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the client@0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote: 
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.SgBaJ/_logs/2020-06-19T18_16_40_663Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 126
remote: npm ERR! readingcom@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 126
remote: npm ERR!
remote: npm ERR! Failed at the readingcom@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.SgBaJ/_logs/2020-06-19T18_16_40_679Z-debug.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        Some possible problems:
remote:
remote:        - node_modules checked into source control
remote:          https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits
remote:
remote:        - Node version not specified in package.json
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to readingcom.
remote:
To https://git.heroku.com/readingcom.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/readingcom.git'

该应用是 MERN 堆栈应用。我已经检查并更新了我的依赖项、heroku CLI 等。

【问题讨论】:

  • 试试这个:$npm install react-scripts --save 然后运行你的应用程序

标签: node.js reactjs heroku


【解决方案1】:

我也遇到了类似的问题。我刚刚使用“npm run build”创建了一个生产构建......然后使用构建文件夹推送节点应用......

在节点应用中配置了这个

app.get('*',(req,res)=>{
  res.sendFile('path to build/index.html');
})

推heroku,它成功了...这是一种hacky方法,并不能真正解决问题,但如果你赶时间,可以试试

【讨论】:

  • 我的 server.js 文件中有这一行。它是一个 MERN 堆栈应用程序 ``` if (process.env.NODE_ENV === 'production') { // 设置静态文件夹 app.use(express.static('client/build')) app.get('*' , (req, res) => res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')) } ``
  • 是的,我的意思是运行“npm run build”,将创建一个构建文件夹,git 跟踪该构建文件夹,从 package.json 中删除 heroku post 脚本并推送 heroku master跨度>
  • 非常感谢。我试了你说的,部署成功了,但是app url显示'not found'
【解决方案2】:

我今天也遇到了这个问题……

在我的研究中,我必须有很多答案可以解决一个问题,但不能解决所有问题......

最后,重新阅读我收到的错误,我注意到 collectstatic 是第一个通知的错误,

运行“$ python manage.py collectstatic --noinput”时出错。

因为它是一个手动可行的查询,所以我使用以下代码手动完成了

./manage.py collectstatic

(要使此命令行正常工作,您必须在 setting.py 中指定 STATIC_ROOT)

setting.py

STATIC_ROOT = os.path.join (BASE_DIR, 'my_static_app_folderName/static')

之后,您必须在部署期间使用命令行禁用此请求的自动执行

heroku config:set DISABLE_COLLECTSTATIC = 1

(对于 Heroku 用户)

然后重新启动

git push heroku master

它应该可以工作......

【讨论】:

    【解决方案3】:

    另一种方式....

    你可以检查你的 git 状态

    $ git status
    

    如果你有一个文件夹必须由 git in 检查

    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            .gitignore
            Procfile
    

    或在

    Changes not staged for commit:
        modified:   store/settings.py
    

    你必须这样做

    $ git add store/
    $ git add Procfile
    

    对于这些部分中的每个文件和文件夹,除了文件 .gitignore... 之后,您再次检查

    $ git status
    

    如果一切正常,现在你可以做

    $ git commit -m "Launching to production"
    

    应用 git 添加...

    验证您的应用配置

    $ heroku config
    

    再试一次

    $ git push heroku master
    

    希望,它会工作!!!

    请原谅我的英语水平

    【讨论】:

      【解决方案4】:

      我在尝试将 create-react-app 部署到 heroku 时遇到了同样的问题。 这是因为我不小心将node_modules 文件夹提交到了我的git 存储库。

      问题解决了

      • 正在运行git rm -r --cached node_modules
      • node_modules/ 添加到.gitignore 文件中
      • 再次提交更改并运行git push heroku master

      【讨论】:

        猜你喜欢
        • 2023-03-30
        • 2021-09-15
        • 1970-01-01
        • 2013-01-25
        • 1970-01-01
        • 1970-01-01
        • 2018-03-27
        • 2012-04-05
        • 1970-01-01
        相关资源
        最近更新 更多