在Heroku上部署Node.js错误:! [远程拒绝]主机->主机(预接收挂钩被拒绝)

时间:2020-03-24 22:56:38

标签: node.js reactjs heroku npm deployment

尝试在Heroku上部署React应用时收到以下错误。我已经将node_modules移至.gitignore,设置了Heroku nodejs buildpack,并更新到了最新版本的node和npm,以确保它们与package.json中的引擎列表匹配。我不知道是什么原因造成的

Enumerating objects: 29163, done.
Counting objects: 100% (29163/29163), done.
Delta compression using up to 4 threads
Compressing objects: 100% (21337/21337), done.
Writing objects: 100% (29163/29163), 31.64 MiB | 711.00 KiB/s, done.
Total 29163 (delta 6397), reused 29163 (delta 6397)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:        
remote: -----> Installing binaries
remote:        engines.node (package.json):  12.16.1
remote:        engines.npm (package.json):   6.4.1
remote:        
remote:        Resolving node version 12.16.1...
remote:        Downloading and installing node 12.16.1...
remote:        Bootstrapping npm 6.4.1 (replacing 6.13.4)...
remote:        npm 6.4.1 installed
remote:        
remote: -----> Installing dependencies
remote:        Prebuild detected (node_modules already exists)
remote:        Rebuilding any native modules
remote:        
remote:        > core-js-pure@3.6.4 postinstall /tmp/build_b4eb2781076772d39a0d97bcbfa078c6/node_modules/core-js-pure
remote:        > node -e "try{require('./postinstall')}catch(e){}"
remote:        
remote:        
remote:        > core-js@3.6.4 postinstall /tmp/build_b4eb2781076772d39a0d97bcbfa078c6/node_modules/core-js
remote:        > node -e "try{require('./postinstall')}catch(e){}"
remote:        
remote:        
remote:        > core-js@2.6.11 postinstall /tmp/build_b4eb2781076772d39a0d97bcbfa078c6/node_modules/babel-runtime/node_modules/core-js
remote:        > node -e "try{require('./postinstall')}catch(e){}"
remote:        
remote:        Installing any new modules (package.json)
remote:        audited 930385 packages in 17.403s
remote:        found 0 vulnerabilities
remote:        
remote:        
remote: -----> Build
remote:        Running build
remote:        
remote:        > project-x@0.1.0 build /tmp/build_b4eb2781076772d39a0d97bcbfa078c6
remote:        > react-scripts build
remote:        
remote:        Creating an optimized production build...
remote:        Failed to compile.
remote:        
remote:        ./src/SocialFollow.js
remote:        Cannot find module: '@fortawesome/react-fontawesome'. Make sure this package is installed.
remote:        
remote:        You can install this package by running: npm install @fortawesome/react-fontawesome.
remote:        
remote:        
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! project-x@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR! 
remote: npm ERR! Failed at the project-x@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.ce7js/_logs/2020-03-25T00_48_13_911Z-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:        - A module may be missing from 'dependencies' in package.json
remote:          https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
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 hidden-stream-53835.
remote: 
To https://git.heroku.com/hidden-stream-53835.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/hidden-stream-53835.git'

package.json

{
  "name": "project-x",
  "version": "0.1.0",
  "private": true,
  "engines": {
    "npm": "6.4.1",
    "node": "12.16.1"
  },
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

2 个答案:

答案 0 :(得分:1)

找不到模块:“ @ fortawesome / react-fontawesome”。确保已安装此软件包。

该软件包未在您的"dependencies"中列出。

通过运行yarn add @fortawesome/react-fontawesomenpm install --save @fortawesome/react-fontawesome并重新部署来添加它。

答案 1 :(得分:0)

您需要添加项目的node和npm版本: 在package.json中添加此行 “引擎”:{ “节点”:“ 10.16.3”, “ npm”:“ 6.9.0” }