简体   繁体   English

将Node JS项目推到heroku时出错

[英]error while pushing node js project to heroku

I am getting this error while I am trying to push my project to heroku. 我在尝试将项目推送到heroku时遇到此错误。 Backend is writtend in nodeJS, frontend in React. 后端使用nodeJS编写,前端使用React编写。 I think the problem is heroku-postbuild, because if I remove it, push works. 我认为问题出在heroku-postbuild,因为如果我删除它,则推送有效。 I was searching for it but still I have no idea what is the reason. 我一直在寻找它,但仍然不知道是什么原因。 Can somebody help me? 有人可以帮我吗?

/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 (server) 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 (client) 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/",
    }

I ran into the similar error while troubleshooting a project. 我在对项目进行故障排除时遇到了类似的错误。 I resolved it by using the suggestions from the prompt. 我通过使用提示中的建议解决了它。

       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

So try do a "rm -rf node_modules" in the root directory if you checked node_modules into the repository. 因此,如果您将node_modules检入到存储库中,请尝试在根目录中执行“ rm -rf node_modules”。 Heroku will install node_modules in the deployed environment and does not need your checked in version. Heroku将在部署的环境中安装node_modules,不需要您的签入版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM