Node.js npm错误!缺少脚本:将react应用程序部署到heroku时生成

Node.js npm错误!缺少脚本:将react应用程序部署到heroku时生成,node.js,reactjs,heroku,deployment,Node.js,Reactjs,Heroku,Deployment,我有一些小的react web应用程序,我正在尝试部署到heroku。我通过youTube视频发现了这一点,据推测这是一种简单的部署方法。作者列出了几个步骤(前两个不适用): git初始化 heroku创建$APP_名称--buildpack git添加 git commit-m“从创建react应用程序开始” git推送heroku主机 赫罗库公开赛 当我到达git push heroku主机时,控制台中会出现一个错误,上面写着: npm ERR! missing script: build

我有一些小的react web应用程序,我正在尝试部署到heroku。我通过youTube视频发现了这一点,据推测这是一种简单的部署方法。作者列出了几个步骤(前两个不适用):

  • git初始化
  • heroku创建$APP_名称--buildpack
  • git添加
  • git commit-m“从创建react应用程序开始”
  • git推送heroku主机
  • 赫罗库公开赛
  • 当我到达git push heroku主机时,控制台中会出现一个错误,上面写着:

    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文件的构建脚本,但它们似乎都不起作用(“构建”:“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帐户。有没有比我在这里做的更简单的方法?

    您提到的
    “构建”:“webpack--config webpack.conf.js”
    不起作用。我猜这就是为什么您在
    包.json中省略了它。这就是解决错误消息所需要的。一旦您在
    包.json中使用了这个脚本,那么一切都应该很好

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

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

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

    反应脚本

    npm i react-scripts --save-dev
    
    确保-dev在那里,以便在服务器启动之前运行

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

    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    
    另外,确保使用正确的构建包也是非常重要的 如果它的唯一反应应用程序no node.js

    但是如果您正在使用node.js构建dual

    heroku buildpacks:clear
    

    并考虑遵循这里的说明

    试试这个:

    "build": "webpack"
    
    我就是从这里弄来的。

    你能分享你的
    包.json吗?我已经更新了我原来的帖子。谢谢
    
    "build": "webpack"