错误的ERR!缺少脚本:在将react应用程序部署到heroku时构建

问题描述 投票:1回答:2

我有一些小的反应网络应用程序,我正在尝试部署到heroku。我通过youTube视频找到了这个https://github.com/mars/create-react-app-buildpack,据说这是一个简单的部署方法。作者列出了几个步骤(前两个不适用):

  1. 去初始化
  2. heroku创建$ APP_NAME --buildpack https://github.com/mars/create-react-app-buildpack.git
  3. git add。
  4. git commit -m“从create-react-app开始”
  5. git push heroku master
  6. heroku开放

一旦我到了git push heroku master,我在控制台中遇到一个错误:

npm ERR! missing script: build
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /app/.npm/_logs/2018-03-26T16_55_19_748Z-debug.log
remote:  !     Push rejected, failed to compile React.js (create-react-app) multi app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to my-simple-react-weather-app.
remote:
To https://git.heroku.com/my-simple-react-weather-app.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/my-simple-react-weather-app.git'

我做了一些搜索并为我的package.json文件找到了一些构建脚本,但它们似乎都没有工作(“”build“:”webpack --config webpack.conf.js“”)

这是我的package.json:

{
  "name": "redux-simple-starter",
  "version": "1.0.0",
  "description": "Simple React YouTube App",
  "main": "index.js",
  "scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "jquery": "^2.2.1",
    "jsdom": "^8.1.0",
    "mocha": "^2.4.5",
    "react-addons-test-utils": "^0.14.7",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "babel-preset-stage-1": "^6.1.18",
    "lodash": "^3.10.1",
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "4.3.0",
    "react-router": "^2.0.1",
    "redux": "^3.0.4",
    "youtube-api-search": "0.0.5"
  }
}

有人可以帮我从这里出去吗?我已经登录了我的heroku帐户。有没有比我在这里做的更简单的方法?

node.js reactjs heroku deployment
2个回答
2
投票

你提到"build": " webpack --config webpack.conf.js"没有用。我猜这就是你从package.json中省略它的原因。这是解决错误消息所需的。一旦你在package.json中使用这个脚本,那么一切都应该是好的。

查看启动脚本,您可能需要通过从.bin目录指定webpack来运行webpack。我不确定您使用的节点版本。

scripts: {
    ...
    "build": "./node_modules/.bin/webpack --config webpack.conf.js",
    ...
}

1
投票

如果您提供git repo,它可能有助于快速解决问题,但现在确保已安装

反应过来的脚本

npm i react-scripts --save-dev

确保-dev在那里,所以它在服务器启动之前运行for more details

另外,保持你的客户端(react app)package.json包括相同的内容

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

如果它只有反应应用程序没有node.js for more details,那么确保你使用正确的buildpack非常重要

heroku create $APP_NAME --buildpack mars/create-react-app

但如果你用node.js构建双重

heroku buildpacks:clear

并考虑按照这里的说明How to use create-react-app with a custom Node server on Heroku

© www.soinside.com 2019 - 2024. All rights reserved.