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

时间:2018-03-26 17:03:35

标签: node.js reactjs heroku deployment

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

  1. git init
  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. 开始
  6. git push heroku master
  7. heroku open
  8. 一旦我到了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"&#34)

    这是我的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帐户。有没有比我在这里做的更简单的方式?

3 个答案:

答案 0 :(得分: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 :(得分:1)

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

反应脚本

arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment)

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

另外,保持您的客户端(react app)package.json包含相同的

npm i react-scripts --save-dev

确保您使用正确的buildpack也是非常重要的 如果仅响应应用程序则没有node.js for more details

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

但是如果您要使用node.js进行双重构建

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

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

答案 2 :(得分:-1)

尝试一下:

"build": "webpack"

这是我从那里得到的。 https://webpack.js.org/guides/getting-started/