根据Heroku日志,React应用程序继续崩溃

时间:2018-01-29 03:00:03

标签: node.js heroku

我已经向Heroku部署了一个React应用程序,这是我的package.json文件:

{
  "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文件:

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文件:

<!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时,我收到此错误:

> 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,但也没有用。我在这里缺少什么想法?

1 个答案:

答案 0 :(得分:0)

我认为这告诉您它无法解析您使用的文件名:  private changeNfcText (message:string) { this.ngZone.run(()=>{ this.nfcText = message; }); } } 您要尝试解决哪个文件名?你只需输入__dirname,就没有指定目录名。我希望你理解