如何用yarn将NodeJS / React应用程序部署到Heroku?

时间:2019-10-28 03:07:29

标签: javascript node.js reactjs heroku deployment

我已经按照heroku上的说明进行了研究,并花了几个小时来研究有关部署到heroku的问题。 每当我将存储库推送到heroku时,构建就无法构建新软件包。

我正在使用纱线包管理器,并向我的应用程序添加了很多依赖项。我在NPM中添加了一个依赖项,并禁止选择两个软件包管理器进行开发。 .. 我已经删除了package-lock.json文件,并将带有脚本的package.json更改为用于我的应用程序的相应包管理器。

{
  "name": "real-world",
  "version": "1",
  "description": "MERN",
  "main": "app.js",
  "author": "Le, Vu Minh",
  "license": "MIT",
  "scripts": {
    "client-install": "yarn --cwd frontend install",
    "start": "node ./app.js",
    "server": "node ./app.js",
    "client": "yarn --cwd ./frontend run start",
    "dev": "concurrently \"yarn run server\" \"yarn run client\"",
    "heroku-postbuild": "yarn install && yarn --cwd ./frontend install && yarn --cwd ./frontend run build"
  },
  "engines": {
    "node": "10.16.0",
    "yarn": "1.19.0"
  },
  "dependencies": {
    "body-parser": "^1.19.0",
    "concurrently": "^5.0.0",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "dotenv": "^8.2.0",
    "errorhandler": "^1.5.1",
    "express": "^4.17.1",
    "express-jwt": "^5.3.1",
    "express-session": "^1.17.0",
    "jshint": "^2.10.2",
    "jsonwebtoken": "^8.5.1",
    "jwt": "^0.2.0",
    "method-override": "^3.0.0",
    "mongoose": "^5.7.4",
    "morgan": "^1.9.1",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "serve": "^11.2.0"
  },
  "devDependencies": {
    "nodemon": "^1.19.3"
  }
}

这是我推送到heroku master分支时的输出。

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):  10.16.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:        engines.yarn (package.json):  1.19.0
remote:
remote:        Resolving node version 10.16.0...
remote:        Downloading and installing node 10.16.0...
remote:        Using default npm version: 6.9.0
remote:        Resolving yarn version 1.19.0...
remote:        Downloading and installing yarn (1.19.0)...
remote:        Installed yarn 1.19.0
remote:
remote: -----> Installing dependencies
remote:        Installing node modules (yarn.lock)
remote:        yarn install v1.19.0
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        info fsevents@1.2.9: The platform "linux" is incompatible with this module.
remote:        info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        [4/4] Building fresh packages...
remote:        error /tmp/build_8fb6cb960e5fba9ed79ab935cf0403ce/node_modules/node-base64: Command failed.
remote:        Exit code: 127
remote:        Command: ./install.sh
remote:        Arguments:
remote:        Directory: /tmp/build_8fb6cb960e5fba9ed79ab935cf0403ce/node_modules/node-base64
remote:        Output:
remote:        ./install.sh: 3: ./install.sh: node-waf: not found
remote:        info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

1 个答案:

答案 0 :(得分:-1)

我有一个类似的问题:一个带有ReactJS的本地应用程序,它使用yarn在本地工作,但是部署到Heroku却不起作用。我浏览了类似的几篇文章,并尝试了一些教程,没有运气。

我认为使用Heroku更好地遵循官方文档。我做了什么:我按照本教程在Heroku中部署了一个简单的React应用程序,然后将代码放入了该应用程序: