成功构建,但部署heroku node.js时出现应用程序错误

时间:2020-09-05 11:25:10

标签: node.js heroku

通过阅读类似文章的答案,主要是Procfile或package.json中的启动脚本出现了问题。但是我都有。尝试了所有内容,但在打开我的网站时仍然出现应用程序错误,我将不胜感激。

在我的机器上,一切正常,但是当我尝试部署该应用程序时,访问URL时出现heroku错误页面。

日志:

-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false
       
-----> Installing binaries
       engines.node (package.json):  v12.18.3
       engines.npm (package.json):   6.14.6
       
       Resolving node version v12.18.3...
       Downloading and installing node 12.18.3...
       npm 6.14.6 already installed with node
       
-----> Restoring cache
       - node_modules
       
-----> Installing dependencies
       Installing node modules
       
       > core-js@2.6.11 postinstall /tmp/build_5ca94f14_/node_modules/babel-runtime/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > fsevents@1.2.13 install /tmp/build_5ca94f14_/node_modules/webpack-dev-server/node_modules/fsevents
       > node install.js
       
       
       Skipping 'fsevents' build as platform linux is not supported
       
       > fsevents@1.2.13 install /tmp/build_5ca94f14_/node_modules/watchpack-chokidar2/node_modules/fsevents
       > node install.js
       
       
       Skipping 'fsevents' build as platform linux is not supported
       
       > core-js@3.6.5 postinstall /tmp/build_5ca94f14_/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > fsevents@1.2.13 install /tmp/build_5ca94f14_/node_modules/jest-haste-map/node_modules/fsevents
       > node install.js
       
       
       Skipping 'fsevents' build as platform linux is not supported
       
       > core-js-pure@3.6.5 postinstall /tmp/build_5ca94f14_/node_modules/core-js-pure
       > node -e "try{require('./postinstall')}catch(e){}"
       
       added 1638 packages in 27.166s
       
-----> Build
       
-----> Caching build
       - node_modules
       
-----> Pruning devDependencies
       audited 1638 packages in 12.176s
       
       65 packages are looking for funding
         run `npm fund` for details
       
       found 0 vulnerabilities
       
       
-----> Build succeeded!
-----> Discovering process types
       Default types for buildpack -> web
-----> Compressing...
       Done: 58.5M
-----> Launching...
       Released v22

我在根目录中有一个Procfile

web:node server.js

package.json:

{
  "name": "react-notes-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "cors": "^2.8.5",
    "express-session": "^1.17.1",
    "md5": "^2.3.0",
    "mysql": "^2.18.1",
    "node-fetch": "^2.6.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "start": "node server.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "engines":{
    "node":"v12.18.3",
    "npm":"6.14.6"
  }
}

Server.js:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const session = require('express-session');
const PORT =  process.env.port || 5000;
const cors = require('cors');
const path = require('path');
var db = require('./db)
var md5 = require('md5');


app.use(express.static(path.join(__dirname, '../build')));



app.get('/', function(req,res) {
  res.sendFile(path.join(__dirname, '../build', 'index.html'));
    });
    
    //some code

app.listen(PORT);

0 个答案:

没有答案