如何让Mern Stack在Heroku上工作 [英] How to get Mern Stack to work on Heroku

查看:143
本文介绍了如何让Mern Stack在Heroku上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试Mern Stack(Mongo Express React / Redux Node),并且在开发时没有问题地进行设置。现在我正在尝试部署到Heroku。我和普通人一样做了一个git push heroku master,但是当我查看网站时,我看到了Heroku的应用程序错误。我通过Heroku添加了MongoDB,并更改了我的heroku配置变量,因此它使用该db(我认为我正确地做了这个)。所以我检查日志:

  npm ERR!文件sh 
npm ERR!代码ELIFECYCLE
npm ERR! errno ENOENT
npm ERR!系统调用产生
npm ERR! mern-starter@1.0.0 start:`cross-env NODE_ENV =开发nodemon index.js`
npm ERR! spawn ENOENT

稍微下降一点:

 > mern-starter@1.0.0 start / app 
> cross-env NODE_ENV =开发nodemon index.js
sh:1:cross-env:未找到



进一步下去:

  npm ERR! Linux 3.13.0-79-generic 
npm ERR! argv/app/.heroku/node/bin/node/app/.heroku/node/bin/npmstart
npm ERR!节点v5.10.0
npm ERR! npm v3.8.3
npm ERR!文件sh
npm ERR!代码ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! mern-starter@1.0.0 start:`cross-env NODE_ENV =开发nodemon index.js`
npm ERR!系统调用产生
npm ERR!产卵ENOENT
npm ERR!
npm ERR!在mern-starter@1.0.0启动脚本'cross-env NODE_ENV =开发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 - 编译器js:babel-register --recursive server / tests / ** / *。spec.js,
start:cross-env NODE_ENV = development nodemon index.js,
start :prod:cross-env NODE_ENV =生产节点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 =生产webpack --config webpack.config。 prod.js& npm run minify,
clean:rimraf static / dist,
slate:rimraf node_modules&& npm install,
lint:eslint cli ent服务器共享

那我该如何解决这个问题?



编辑:

 devDependencies:{
babel- eslint:^ 5.0.0-beta6,
babel-loader:^ 6.2.1,
babel-plugin-react-transform:^ 2.0.0,
babel-plugin-transform-react-inline-elements:6.6.5,
babel-plugin-transform-react-inline-elements $ bbabel-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-plugi n-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
},


解决方案我在这里写了: https:// hashnode。 com / post /部署-mern-to-heroku-success-cio7sc1py013nis531rg3lfmz



原因是因为herokou不知道你的 devDependencies 树,只有你的常规依赖关系被推送。



快速解决方法是将所有 devDependencies 复制到您的依赖关系中



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




public / *
static / dist
static / css / app.min.css



我在文章中列出了一些其他步骤,但这些是它们在没有一些额外配置的情况下无法正常工作的主要原因。


I'm testing out the Mern Stack (Mongo Express React/Redux Node) and set it up with development with no issue. Now I'm trying to deploy to Heroku. I did a git push heroku master just like normal, but when I check out the website I see Heroku's Application Error. I added a MongoDB through Heroku, and changed my heroku config variables, so it uses that db (I think I did this correctly). So I check into logs:

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

A little way down:

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

Further down:

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'.

So I don't know as much about the back end, but it appears to be running the development script in 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"
  }

So how can I get this to work?

EDIT:

"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"
  },

解决方案

I wrote about it here: https://hashnode.com/post/deploying-mern-to-heroku-success-cio7sc1py013nis531rg3lfmz

The reason is because herokou does not know about your devDependencies tree, only your regular dependencies get pushed.

A quick fix is to copy all of your devDependencies to your dependencies

You will also have to remove the following from the .gitignore file:

public/* static/dist static/css/app.min.css

There are a couple other steps I outlined in the article, but those are the primary reasons it won't work without some extra configurations.

这篇关于如何让Mern Stack在Heroku上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆