如何让Mern Stack在Heroku上工作

时间:2016-04-13 23:53:00

标签: heroku reactjs production react-redux mern

我正在测试Mern Stack(Mongo Express React / Redux节点)并将其设置为开发没有问题。现在我尝试部署到Heroku。我像正常一样做了一个git push heroku master,但是当我查看网站时,我看到了Heroku的应用程序错误。我通过Heroku添加了一个MongoDB,并更改了我的heroku配置变量,因此它使用了该数据库(我想我是这样做的)。所以我查看日志:

npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! mern-starter@1.0.0 start: `cross-env NODE_ENV=development nodemon index.js`
npm ERR! spawn ENOENT

一点点下来:

 > mern-starter@1.0.0 start /app
 > cross-env NODE_ENV=development nodemon index.js
   sh: 1: cross-env: not found

再向下:

npm ERR! Linux 3.13.0-79-generic
npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
npm ERR! node v5.10.0
npm ERR! npm  v3.8.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! mern-starter@1.0.0 start: `cross-env NODE_ENV=development nodemon index.js`
npm ERR! syscall spawn
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the mern-starter@1.0.0 start script 'cross-env NODE_ENV=development nodemon index.js'.

所以我不太了解后端,但似乎是在package.json中运行开发脚本:

"scripts": {
    "test": "mocha shared/tests/*.spec.js --compilers js:babel-register",
    "test:server": "cross-env NODE_ENV=test PORT=8080 MONGO_URL=mongodb://localhost:27017/mern-test mocha --compilers js:babel-register --recursive server/tests/**/*.spec.js",
    "start": "cross-env NODE_ENV=development nodemon index.js",
    "start:prod": "cross-env NODE_ENV=production node index.js",
    "bs": "npm run clean && npm run build && npm run start:prod",
    "minify": "cleancss -o static/css/app.min.css static/css/app.css",
    "build": "cross-env NODE_ENV=production webpack --config webpack.config.prod.js && npm run minify",
    "clean": "rimraf static/dist",
    "slate": "rimraf node_modules && npm install",
    "lint": "eslint client server shared"
  }

那我怎么能让它发挥作用呢?

编辑:

"devDependencies": {
    "babel-eslint": "^5.0.0-beta6",
    "babel-loader": "^6.2.1",
    "babel-plugin-react-transform": "^2.0.0",
    "babel-plugin-transform-react-constant-elements": "6.5.0",
    "babel-plugin-transform-react-inline-elements": "6.6.5",
    "babel-plugin-transform-react-remove-prop-types": "0.2.4",
    "babel-polyfill": "^6.3.14",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-react-hmre": "^1.1.0",
    "babel-register": "^6.7.2",
    "chai": "^3.5.0",
    "clean-css": "^3.4.9",
    "cross-env": "^1.0.7",
    "css-loader": "^0.23.1",
    "css-modules-require-hook": "^2.1.0",
    "deep-freeze": "0.0.1",
    "eslint": "^1.10.3",
    "eslint-config-airbnb": "^4.0.0",
    "eslint-plugin-react": "^3.16.1",
    "expect": "^1.13.4",
    "expect-jsx": "^2.2.2",
    "extract-text-webpack-plugin": "^1.0.1",
    "mocha": "^2.4.5",
    "nodemon": "^1.9.1",
    "pre-commit": "^1.1.2",
    "react-addons-test-utils": "^0.14.7",
    "react-transform-hmr": "^1.0.1",
    "redux-devtools": "^3.1.1",
    "redux-devtools-dock-monitor": "^1.1.0",
    "redux-devtools-log-monitor": "^1.0.4",
    "rimraf": "^2.5.1",
    "style-loader": "^0.13.0",
    "supertest": "^1.1.0",
    "webpack": "^1.12.12",
    "webpack-dev-middleware": "^1.5.1",
    "webpack-hot-middleware": "^2.6.4"
  },

1 个答案:

答案 0 :(得分:1)

我在这里写到:https://hashnode.com/post/deploying-mern-to-heroku-success-cio7sc1py013nis531rg3lfmz

原因是因为herokou不了解您的protected bool _isRotating = false; /// <summary> /// Rotates the hand around a specific point /// </summary> /// <param name="point">The point to rotate around</param> /// <param name="perspective"> /// The perspective view in which the transform occurs, by default this is Camera.Main /// </param> public IEnumerator RotateHand(GameHelper.Axis axis, bool isPositiveDirection, Vector3 isolatedRotationPoint, float inTime = 1f, int degrees = GameHelper.RIGHT_ANGLE_DEGREES, Transform perspective = null) { if (_isRotating) { yield break; } _isRotating = true; var targetPerspective = perspective ?? Camera.main.transform; int charge = isPositiveDirection ? 1 : -1; int normalizedDegrees = degrees * charge; var noralizedAxisVector = this.GetNormalizeHandVector(axis, targetPerspective);; var perfectAngles = transform.eulerAngles + (noralizedAxisVector * normalizedDegrees); var perfectedAngles = new Vector3(perfectAngles.x, perfectAngles.y, perfectAngles.z); float endTime = Time.time + inTime; while (Time.time < endTime) { var delta = normalizedDegrees * (Time.deltaTime / inTime); transform.RotateAround(isolatedRotationPoint, noralizedAxisVector, delta); Debug.Log(transform.rotation); yield return null; } //Gimbal Lock, correct end values for loss in floating point percision transform.eulerAngles = perfectedAngles; Debug.Log(transform.rotation); _isRotating = false; } 树,只有您的常规devDependencies被推送。

快速解决方法是将所有dependencies复制到devDependencies

您还必须从dependencies文件中删除以下内容:

.gitignore

我在文章中概述了其他几个步骤,但这些是在没有额外配置的情况下无法工作的主要原因。