node.js - 将 Node js 项目推送到 heroku 时出错

标签 node.js reactjs heroku

当我尝试将我的项目推送到heroku 时,我收到此错误。后端是用nodeJS编写的,前端是用React编写的。我认为问题是heroku-postbuild,因为如果我删除它,推送就会起作用。我一直在寻找它,但我仍然不知道是什么原因。有人可以帮助我吗?

/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: MZ����@: not found
/tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: 1: /tmp/build_7504975f08f330415cdefb27437cfad9/node_modules/.bin/node: Syntax error: word unexpected (expecting ")")
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project@1.0.0 heroku-postbuild: `cd client && npm install && npm run build`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the project@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.W89m8/_logs/2018-11-13T21_37_22_676Z-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

       Some possible problems:

       - node_modules checked into source control
         https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits

       - Node version not specified in package.json
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

       Love,
       Heroku

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

package.json(服务器)

    {
      "name": "project",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "start": "node server.js",
        "server": "nodemon server.js",
        "client-install": "npm install --prefix client",
        "client": "npm start --prefix client",
        "dev": "concurrently \"npm run server\" \"npm run client\"",
        "heroku-postbuild": "cd client && npm install && npm run build"
      },

      "author": "",
      "license": "ISC",
      "dependencies": {
        "concurrently": "^4.0.1",
        "express": "^4.16.4",
        "jsonwebtoken": "^8.3.0",
        "mongoose": "^5.3.4",
        "node": "^8.10.0",
        "nodemon": "^1.18.4",
        "passport": "^0.4.0",
        "passport-jwt": "^4.0.0",
        "react-scripts": "1.0.11",
      },
      "devDependencies": {
        "nodemon": "^1.18.4",
        "react-scripts": "1.0.11"
      }
    }

package.json(客户端)

{
      "name": "client",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "parallelshell": "^3.0.2",
        "react-dom": "^16.5.2",
        "react-redux": "^5.0.7",
        "react-router": "^4.3.1",
        "react-router-dom": "^4.3.1",
        "react-router-redux": "^4.0.8",
        "react-scripts": "2.0.5",
        "socket.io-client": "^1.7.3",
      },
      "scripts": {
        "start": "parallelshell \"react-scripts start\" \"sass --watch src/styles/scss:src/styles/css --style compressed\"",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "sass": "sass --watch src/styles/scss:src/styles/css --style compressed",
        "sass-nw": "sass src/styles/scss:src/styles/css"
      },
      "proxy": "http://localhost:5000/",
    }

最佳答案

我在对项目进行故障排除时遇到了类似的错误。我通过使用提示中的建议解决了这个问题。

       Some possible problems:

   - node_modules checked into source control
     https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits

   - Node version not specified in package.json
     https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

因此,如果您将node_modules checkin 存储库,请尝试在根目录中执行“rm -rf node_modules”。 Heroku 将在部署的环境中安装 node_modules,不需要您 checkin 的版本。

关于node.js - 将 Node js 项目推送到 heroku 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53290110/

相关文章:

javascript - 如何在 node.js 中使用 sqlite3 - 什么是 smt?

MySQL - insert into... on duplicate key update - 如何区分插入或更新?

使用 Node Express 在 digital ocean 中设置 mysql

ruby-on-rails - 如何修复 Linux 的 Windows 子系统上的 'ECONNRESET: socket hang up'?

heroku - AWS、Heroku 与其他可扩展平台?

javascript - 是否可以在整个 Node Express 服务器上定义一个全局变量?

javascript - React JS 如何重置表单

javascript - React JS 中的菜单切换

android - backAndroid/backHandler 适用于每个屏幕 - React Native

deployment - therubyracer 无法在 heroku 上构建