Node / React应用程序不会部署到Heroku

时间:2017-06-23 12:31:13

标签: node.js reactjs express heroku

我的应用有一个React前端和一个Node后端; BE通过API提供FE数据。它不会部署到Heroku-stack跟踪下面。

我尝试的事情:

  1. This question。我在答案中提到的模型回购后尝试对我的package.json文件进行建模,但没有运气。
  2. 部署上面提到的模型仓库 - 工作正常。
  3. 将模型仓库部署到我自己的失败的heroku应用程序 - 它工作正常,所以Heroku不是问题。
  4. This question(我已经检查过react-scripts被列为依赖项,而不是dev依赖项。
  5. 我可能最终将模型仓库作为起点并逐渐复制我的项目,但会欣赏任何可能出错的信息。

    堆栈追踪:

    > fsevents@1.0.17 install /tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fsevents
    > node-pre-gyp install --fallback-to-build
    
    node-pre-gyp ERR! Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v48-linux-x64.tar.gz
    node-pre-gyp ERR! Pre-built binaries not found for fsevents@1.0.17 and node@6.10.3 (node-v48 ABI) (falling back to source compile with node-gyp)
    make: Entering directory '/tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fsevents/build'
    SOLINK_MODULE(target) Release/obj.target/.node
    COPY Release/.node
    make: Leaving directory '/tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fsevents/build'
    
    > fibers@1.0.15 install /tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client/node_modules/fibers
    > node build.js || nodejs build.js
    
    `linux-x64-48` exists; testing
    Binary is fine; exiting
    added 1242 packages in 52.433s
    removed 1242 packages in 25.561s
    
    > react-ui@0.1.0 build /tmp/build_f03b382a2b768aeb89ff9c197145d0a5/client
    > react-scripts build
    
    sh: 1: react-scripts: not found
    npm ERR! file sh
    npm ERR! code ELIFECYCLE
    npm ERR! errno ENOENT
    npm ERR! syscall spawn
    npm ERR! react-ui@0.1.0 build: `react-scripts build`
    npm ERR! spawn ENOENT
    npm ERR!
    npm ERR! Failed at the react-ui@0.1.0 build script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    

    我的服务器package.json:

    {
      "name": "in-search-of-happiness",
      "engines": {
        "node": "6.10.x"
      },
      "version": "0.0.0",
      "private": true,
      "scripts": {
        "start": "node ./bin/www",
        "heroku-postbuild": "cd client/ && npm install --only=dev && npm install && npm run build"
      },
      "cacheDirectories": [
        "node_modules",
        "client/node_modules"
      ],
      "dependencies": {
        "body-parser": "^1.17.2",
        "cookie-parser": "^1.4.3",
        "debug": "~2.6.3",
        "express": "~4.15.2",
        "jade": "^1.11.0",
        "mongoose": "^4.10.8",
        "morgan": "^1.8.2",
        "serve-favicon": "^2.4.3",
        "zombie": "^5.0.5"
      }
    }
    

    My React package.json:

    {
      "name": "react-ui",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "bootstrap": "^3.3.7",
        "fetch": "^1.1.0",
        "node-fetch": "^1.7.1",
        "process-nextick-args": "^1.0.7",
        "react": "^15.6.1",
        "react-bootstrap": "^0.31.0",
        "react-dom": "^15.6.1",
        "react-scripts": "1.0.7",
        "util-deprecate": "^1.0.2"
      },
      "devDependencies": {
        "chai": "^4.0.2",
        "eslint": "^4.0.0",
        "sinon": "^2.3.5",
        "wdio-mocha-framework": "^0.5.10",
        "webdriverio": "^4.8.0"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      },
      "proxy": "http://localhost:3001"
    }
    

1 个答案:

答案 0 :(得分:0)

您好,您的后期制作脚本需要进行一些修改,请遵循以下约定

将reactFolderName替换为包含react前端的文件夹名称 将以下代码段添加到脚本下的package.json中

    scripts{
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix reactFolderName && npm run build --prefix reactFolderName"
}

并将此代码段添加到index.js文件中

    app = express()
    app.use(express.static('reactFolderName/build'));
    app.get('*', (req, res) => res.sendFile(path.resolve(__dirname, 'reactFolderName', 'build', 'index.html')));