首页 > 解决方案 > 部署 heroku 错误:未能将一些引用推送到

问题描述

我试图将带有socket.io的react-app部署到heroku
,但出现错误:无法将一些参考推送到....
我尝试过
的内容--删除纱线文件。所以没有重复。
-我尝试从主目录和主目录推送它
- 在我的目录中,我有 2 个文件夹 - 客户端和服务器。我不确定我需要从哪一个中执行此操作):或者我需要在主文件夹中执行此操作?无论如何我都试过了
请让我知道我应该放在这里的代码中是否还有其他内容

`$ git push heroku master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 473 bytes | 157.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  v14.16.1
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version v14.16.1...
remote:        Downloading and installing node 14.16.1...
remote:        Using default npm version: 6.14.12
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules
remote:        npm ERR! fsevents not accessible from jest-haste-map
remote:
remote:        npm ERR! A complete log of this run can be found in:
remote:        npm ERR!     /tmp/npmcache.nNjQb/_logs/2021-09-21T08_50_12_443Z-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:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote: 
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built: 1a127e4f9bb391435a03b5b01efc834477d48c20        
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 1a127e4f9bb391435a03b5b01efc834477d48c20
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote:
remote: Verifying deploy...
remote: 
remote: !       Push rejected to secret-shelf-34629.
remote:
To https://git.heroku.com/secret-shelf-34629.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/secret- 
   shelf-34629.git'`

在服务器文件夹上:

{
  "dependencies": {
    "express": "^4.17.1",
    "socket.io": "^4.2.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.12"
  },
  "name": "server",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "devStart": "nodemon server.js"
  },
  "engines": {
    "node": "v14.16.1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

server.js:

const path = require('path');
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
const port = process.env.PORT || 3000;

app.use(express.static(path.join(__dirname, '../../build')));

app.get('/', (req, res, next) => res.sendFile(__dirname + './index.html'));
io.on("connection", socket => {
    const id = socket.handshake.query.id
    socket.join(id)

    socket.on("send-message", ({ recipients, text }) => {
        recipients.forEach(recipient => {
            const newRecipients = recipients.filter(r => r !== recipient)
            newRecipients.push(id)
            socket.broadcast.to(recipient).emit("recive-message", {
                recipients: newRecipients, sender: id, text
            })
        })
    })
})

server.listen(port);

客户端包.json

{
  "name": "five",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "bootstrap": "^5.1.1",
    "express": "^4.17.1",
    "react": "^17.0.2",
    "react-bootstrap": "^1.6.3",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "socket.io": "^4.2.0",
    "socket.io-client": "^4.2.0",
    "uuid": "^8.3.2",
    "web-vitals": "^1.0.1"
  },
  "engines": {
    "node": "v14.16.1"
  },
  "scripts": {
    "start": "node client/server.js",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

标签: reactjsheroku

解决方案


推荐阅读