根据Heroku日志,React应用程序继续崩溃 [英] React apps continue crashing according to Heroku logs

查看:55
本文介绍了根据Heroku日志,React应用程序继续崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将React应用程序部署到Heroku,这是我的package.json文件:

I have deployed a React application to Heroku and this is my package.json file:

{
  "name": "efUtube",
  "version": "1.0.0",
  "description": "Simple starter package for Redux with React and Babel support",
  "main": "index.js",
  "repository": "git@github.com:ldco2016/efUtube.git",
  "scripts": {
    "dev": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "start": "node server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch"
  },
  "engines": {
    "node": "9.3.0",
    "npm": "5.6.0"
  },
  "author": "Daniel Cortes",
  "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": "3.0.0",
    "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",
    "express": "4.16.2",
    "lodash": "^3.10.1",
    "node": "9.4.0",
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "^4.0.0",
    "react-router": "^2.0.1",
    "redux": "^3.0.4",
    "youtube-api-search": "0.0.5"
  }
}

这是我的server.js文件:

This is my server.js file:

const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();

app.use(express.static(__dirname));

app.get('*', (req, res) => {
  res.sendFile(path.resolve(__dirname, 'index.html'))
});

app.listen(port);
console.log('Server started');

这是我的index.html文件:

This is my index.html file:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="/style/style.css">
    <link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css">
    <script src="https://maps.googleapis.com/maps/api/js"></script>
  </head>
  <body>
    <div class="container"></div>
  </body>

</html>

它已成功部署到Heroku,但浏览器屏幕一片空白.当我查看heroku logs时,出现此错误:

It successfully deploys to Heroku, but I get nothing but a blank browser screen. When I look at heroku logs, I get this error:

> efUtube@1.0.0 start /app
2018-01-29T02:46:25.789611+00:00 app[web.1]:     throw err;
2018-01-29T02:46:25.707212+00:00 app[web.1]: > node server.js
2018-01-29T02:46:25.707213+00:00 app[web.1]:
2018-01-29T02:46:25.789608+00:00 app[web.1]: module.js:557
2018-01-29T02:46:25.789618+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:555:15)
2018-01-29T02:46:25.789613+00:00 app[web.1]:     ^
2018-01-29T02:46:25.789614+00:00 app[web.1]:
2018-01-29T02:46:25.789616+00:00 app[web.1]: Error: Cannot find module 'express'
2018-01-29T02:46:25.789624+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:1:79)
2018-01-29T02:46:25.789620+00:00 app[web.1]:     at Function.Module._load (module.js:482:25)
2018-01-29T02:46:25.789621+00:00 app[web.1]:     at Module.require (module.js:604:17)
2018-01-29T02:46:25.789622+00:00 app[web.1]:     at require (internal/module.js:11:18)
2018-01-29T02:46:25.789625+00:00 app[web.1]:     at Module._compile (module.js:660:30)
2018-01-29T02:46:25.789627+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:671:10)
2018-01-29T02:46:25.789628+00:00 app[web.1]:     at Module.load (module.js:573:32)
2018-01-29T02:46:25.789631+00:00 app[web.1]:     at Function.Module._load (module.js:505:3)
2018-01-29T02:46:25.794695+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-01-29T02:46:25.789630+00:00 app[web.1]:     at tryModuleLoad (module.js:513:12)
2018-01-29T02:46:25.795166+00:00 app[web.1]: npm ERR! errno 1
2018-01-29T02:46:25.797006+00:00 app[web.1]: npm ERR! efUtube@1.0.0 start: `node server.js`
2018-01-29T02:46:25.797239+00:00 app[web.1]: npm ERR! Exit status 1
2018-01-29T02:46:25.797542+00:00 app[web.1]: npm ERR!
2018-01-29T02:46:25.797793+00:00 app[web.1]: npm ERR! Failed at the efUtube@1.0.0 start script.
2018-01-29T02:46:25.798024+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-01-29T02:46:25.802987+00:00 app[web.1]:
2018-01-29T02:46:25.803185+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-01-29T02:46:25.803309+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-01-29T02_46_25_799Z-debug.log
2018-01-29T02:46:25.865590+00:00 heroku[web.1]: Process exited with status 1

我做了npm install expressnpm install express --save,但这两个也不起作用.有什么想法我在这里想念的吗?

I did npm install express and npm install express --save, that did not work either. Any ideas what I am missing here?

推荐答案

我认为这是在告诉您无法在使用文件的位置解析文件名: app.use(express.static(__dirname)) 您要解析到哪个文件名?您只输入了__dirname,没有指定目录名.希望你能理解

I think this is telling you it can't resolve the file name where you using: app.use(express.static(__dirname)) Which file name are you trying to resolve to there? You just put __dirname, you didn't specify the directory name. I hope you understand

这篇关于根据Heroku日志,React应用程序继续崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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