javascript - 如何使用 yarn 将 NodeJS/React 应用程序部署到 Hero

我已经按照 heroku 上的说明进行了研究,并研究了几个小时以找到有关部署到 heroku 的问题。 每当我将存储库推送到 heroku 时,构建都会在构建新包时失败。

我正在使用 yarn 包管理器并向我的应用程序添加了很多依赖项。我添加了一个与 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.

最佳答案

您应该删除 package-lock.json 并改为包含 yarn.lock,heroku 将使用 yarn 而不是 npm 进行部署。

关于javascript - 如何使用 yarn 将 NodeJS/React 应用程序部署到 Heroku?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58585347/

相关文章:

azure-devops - "kubeconfig"选项的 Azure Devops kubern

python-3.x - 模块错误 : Rasterio has no attribute open

python - Jupyterhub-错误 :asyncio:Task exception was

python - 在 Python 中打印大型 JSON 文件的前几行

c# - .Net Core Linux 不支持 SecurityIdentifier?

reactjs - react Apollo 测试 : MockProvider takes a l

python - Jupyter 循环播放声音

amazon-web-services - Cloudwatch 中未显示 Cognito 的指标

django - 重定向到 Django Admin 中的过滤列表

postgresql - 通过 EC2 从 sqlalchemy 连接 AWS RDS