首页 > 解决方案 > !推送被拒绝,无法编译 Node.js 应用程序。!推送失败

问题描述

我一直在尝试将我的 react 网站推送到 heroku,但它不会让我成功,但我已经成功地将它推送到了 github。我也更新了我的节点版本,但似乎没有任何效果。这个网站上有关于同一问题的类似问题,我也按照他们的步骤进行操作,但似乎没有任何效果

sh: 1: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! portfolio@1.0.0 heroku-postbuild: `ng build --prod`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the portfolio@1.0.0 heroku-postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.XmdM7/_logs/2020-02-21T00_18_42_925Z-debug.log
-----> Build failed

       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/

       Love,
       Heroku

 !     Push rejected, failed to compile Node.js app.
 !     Push failed


here's my package.json file

{
  "name": "portfolio",
  "version": "1.0.0",
  "engines": {
    "node": "12.16.1",
    "npm": "6.13.4"
  },
  "description": "A clean, beautiful and responsive portfolio template for Developers!",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config webpack.dev.js --open",
    "build": "webpack --config webpack.prod.js",
    "heroku-postbuild": "ng build --prod"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/mkhawark/portfolio.git"
  },
  "keywords": [],
  "author": "Mohammad Khawar",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/mkhawark/portfolio/issues"
  },
  "homepage": "https://github.com/mkhawark/portfolio#readme",
  "devDependencies": {
    "clean-webpack-plugin": "^3.0.0",
    "css-loader": "^3.4.1",
    "file-loader": "^5.0.2",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "mini-css-extract-plugin": "^0.9.0",
    "node-sass": "^4.13.0",
    "optimize-css-assets-webpack-plugin": "^5.0.3",
    "sass-loader": "^8.0.0",
    "style-loader": "^1.1.2",
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.10.1",
    "webpack-merge": "^4.2.2"
  },
  "dependencies": {
    "bootstrap": "^4.4.1",
    "jquery": "^3.4.1",
    "popper.js": "^1.16.0",
    "tilt.js": "^1.2.1"
  }
}

标签: node.jsreactjsherokunpm

解决方案


你读过这个:https ://devcenter.heroku.com/articles/getting-started-with-nodejs

看起来您的启动脚本只是启动了开发服务器,但是使用 heroku,您必须提供实际的构建文件。

您必须构建项目,然后使用简单的服务器静态提供构建文件夹。这是我的一个项目中的示例设置,请注意 npm start 只会触发快速服务器 index.js:https ://github.com/mattberg88/genome-project/tree/heroku


推荐阅读