【问题标题】:Heroku error cant resolve: error Command "build" not foundHeroku错误无法解决:找不到错误命令“build”
【发布时间】:2019-11-28 14:48:34
【问题描述】:

我正在尝试部署我的小型全栈应用程序。文件结构是这样的。我使用的是节点服务器,客户端文件夹是由 create-react-app 创建的。

\MyApp
  \server.js
  \package.json
  \client
    \package.json

我的外部 package.json 脚本如下所示:

 "scripts": {
   "client": "cd client && yarn start",
   "server": "nodemon server.js",
   "dev": "concurrently --kill-others-on-fail \"yarn server\" \"yarn 
   client\"",
   "dev:server": "cd client && yarn build && cd .. && yarn start",
   "start": "node server.js",
   "heroku-postbuild": "cd client && yarn install && yarn install -- 
    only=dev --no-shrinkwrap && yarn run build"
  },

我的客户端 package.json 脚本如下所示:

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
},

但是当我尝试在 heroku 上部署我的应用时,它会引发以下错误:

warning package.json: No license field
error Command "build" not found.
   info Visit https://yarnpkg.com/en/docs/cli/run for documentation  
 about this command.
 error Command failed with exit code 1.
   info Visit https://yarnpkg.com/en/docs/cli/run for documentation 
 about this command.
 -----> Build failed

   We're sorry this build is failing! You can troubleshoot common .   
   issues here:
   https://devcenter.heroku.com/articles/troubleshooting-node-deploys

   If you're stuck, please submit a ticket so we can help:
   https://help.heroku.com/

   Love,
   Heroku

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

我不明白我在这里做错了什么。

【问题讨论】:

  • 感谢您提出这个问题????

标签: node.js reactjs heroku deployment create-react-app


【解决方案1】:

我遇到了完全相同的问题,我尝试了一些方法来解决这个问题。最后我发现这是因为客户端文件夹作为子模块存在于我的 github 存储库中。所以我将客户端更改为普通文件夹,并推送到 heroku 工作。我建议你的步骤:

  1. 检查 github 存储库中客户端文件夹的状态

  2. 如果客户端文件夹是子模块(不可点击),请执行后续步骤

2-1。删除客户端文件夹中的 .git 文件夹 (cd client && rm -rf .git)

2-2。删除远程客户端文件夹缓存 (git rm -r --cache client)

2-3。添加、提交和推送到远程存储库 (git add . && git commit && git push)。所以改变你的客户文件夹状态

  1. 终于推送到heroku (git push heroku master)

我认为可能是 heroku 无法访问和执行子模块的命令。如果这几个步骤工作正常,请告诉我。

【讨论】:

  • OMG,你是救命稻草,困扰了我2天终于到了,git rm -r --cache client为我做了这个工作,非常感谢
猜你喜欢
  • 2018-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-10
  • 2021-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多