gpt4 book ai didi

node.js - 使用 mongoose 在 Heroku 上托管 Express 应用程序时出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:08:27 25 4
gpt4 key购买 nike

我正在使用 ionic 2 构建一个平均堆栈应用程序,我想将其托管在 Heroku 上。该应用程序已完成并在本地运行良好,我已将其连接到 mLabs 数据库。当我将应用程序推送到 Heroku 时,我在日志中收到以下错误。

2017-04-10T12:32:15.558949+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2017-04-10T12:32:15.558953+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-04-10T12:32:15.558954+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-10T12:32:15.558951+00:00 app[web.1]: at Function.Module._load (module.js:417:25)
2017-04-10T12:32:15.558952+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-04-10T12:32:15.558952+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:4:16)
2017-04-10T12:32:15.558951+00:00 app[web.1]: at Module.require (module.js:497:17)
2017-04-10T12:32:15.558954+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-10T12:32:15.558955+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-10T12:32:15.558955+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-10T12:32:15.558950+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
2017-04-10T12:32:15.567486+00:00 app[web.1]:
2017-04-10T12:32:15.577504+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-04-10T12:32:15.577867+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-04-10T12:32:15.578113+00:00 app[web.1]: npm ERR! node v6.10.2
2017-04-10T12:32:15.578341+00:00 app[web.1]: npm ERR! npm v3.10.10
2017-04-10T12:32:15.578578+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-04-10T12:32:15.578785+00:00 app[web.1]: npm ERR! ionic-hello-world@ start: `node server.js`
2017-04-10T12:32:15.578954+00:00 app[web.1]: npm ERR! Exit status 1
2017-04-10T12:32:15.579249+00:00 app[web.1]: npm ERR!
2017-04-10T12:32:15.579426+00:00 app[web.1]: npm ERR! Failed at the ionic-hello-world@ start script 'node server.js'.
2017-04-10T12:32:15.579621+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-04-10T12:32:15.579920+00:00 app[web.1]: npm ERR! not with npm itself.
2017-04-10T12:32:15.579746+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
2017-04-10T12:32:15.580101+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-04-10T12:32:15.580265+00:00 app[web.1]: npm ERR! node server.js
2017-04-10T12:32:15.580757+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-04-10T12:32:15.580428+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-04-10T12:32:15.580601+00:00 app[web.1]: npm ERR! npm bugs ionic-hello-world
2017-04-10T12:32:15.580878+00:00 app[web.1]: npm ERR! npm owner ls ionic-hello-world
2017-04-10T12:32:15.580993+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-04-10T12:32:15.588769+00:00 app[web.1]:
2017-04-10T12:32:15.589345+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-04-10T12:32:15.589646+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-04-10T12:32:15.679397+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:32:15.680194+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T12:32:15.673049+00:00 heroku[web.1]: Process exited with status 1
2017-04-10T12:32:18.568796+00:00 heroku[web.1]: Starting process with command `npm start`
2017-04-10T12:32:21.743026+00:00 app[web.1]:
2017-04-10T12:32:21.743041+00:00 app[web.1]: > ionic-hello-world@ start /app
2017-04-10T12:32:21.743042+00:00 app[web.1]: > node server.js
2017-04-10T12:32:21.743042+00:00 app[web.1]:
2017-04-10T12:32:22.058223+00:00 app[web.1]: module.js:471
2017-04-10T12:32:22.058237+00:00 app[web.1]: ^
2017-04-10T12:32:22.058236+00:00 app[web.1]: throw err;
2017-04-10T12:32:22.058239+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2017-04-10T12:32:22.058238+00:00 app[web.1]:
2017-04-10T12:32:22.058241+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15)
2017-04-10T12:32:22.058242+00:00 app[web.1]: at Function.Module._load (module.js:417:25)
2017-04-10T12:32:22.058242+00:00 app[web.1]: at Module.require (module.js:497:17)
2017-04-10T12:32:22.058243+00:00 app[web.1]: at require (internal/module.js:20:19)
2017-04-10T12:32:22.058243+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:4:16)
2017-04-10T12:32:22.058244+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-04-10T12:32:22.058245+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-04-10T12:32:22.058245+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-04-10T12:32:22.058246+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-04-10T12:32:22.058246+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-04-10T12:32:22.067921+00:00 app[web.1]:
2017-04-10T12:32:22.080492+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-04-10T12:32:22.080827+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-04-10T12:32:22.080991+00:00 app[web.1]: npm ERR! node v6.10.2
2017-04-10T12:32:22.081154+00:00 app[web.1]: npm ERR! npm v3.10.10
2017-04-10T12:32:22.081323+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-04-10T12:32:22.081657+00:00 app[web.1]: npm ERR! Exit status 1
2017-04-10T12:32:22.081825+00:00 app[web.1]: npm ERR!
2017-04-10T12:32:22.081993+00:00 app[web.1]: npm ERR! Failed at the ionic-hello-world@ start script 'node server.js'.
2017-04-10T12:32:22.082162+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-04-10T12:32:22.081490+00:00 app[web.1]: npm ERR! ionic-hello-world@ start: `node server.js`
2017-04-10T12:32:22.082332+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
2017-04-10T12:32:22.082335+00:00 app[web.1]: npm ERR! not with npm itself.
2017-04-10T12:32:22.082498+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-04-10T12:32:22.082666+00:00 app[web.1]: npm ERR! node server.js
2017-04-10T12:32:22.082832+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-04-10T12:32:22.083001+00:00 app[web.1]: npm ERR! npm bugs ionic-hello-world
2017-04-10T12:32:22.083168+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-04-10T12:32:22.083170+00:00 app[web.1]: npm ERR! npm owner ls ionic-hello-world
2017-04-10T12:32:22.083338+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-04-10T12:32:22.092234+00:00 app[web.1]:
2017-04-10T12:32:22.092236+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-04-10T12:32:22.092237+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2017-04-10T12:32:22.188511+00:00 heroku[web.1]: Process exited with status 1
2017-04-10T12:32:22.201942+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:32:50.415338+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-69141.herokuapp.com request_id=898a0974-f3eb-47b2-a7ca-77a37cf99131 fwd="193.1.57.4" dyno= connect= service= status=503 bytes= protocol=https
2017-04-10T12:35:00.000000+00:00 app[api]: Build started by user alanmurphy1995@gmail.com
2017-04-10T12:36:27.620672+00:00 app[api]: Release v6 created by user alanmurphy1995@gmail.com
2017-04-10T12:36:27.620672+00:00 app[api]: Deploy 9f02cb4 by user alanmurphy1995@gmail.com
2017-04-10T12:36:27.804049+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T12:36:27.782474+00:00 app[api]: Release v6 created by user alanmurphy1995@gmail.com
2017-04-10T12:35:00.000000+00:00 app[api]: Build succeeded
2017-04-10T12:36:33.381932+00:00 heroku[web.1]: Starting process with command `npm start`
2017-04-10T12:36:36.544686+00:00 app[web.1]:
2017-04-10T12:36:36.544709+00:00 app[web.1]: > ionic-hello-world@ start /app
2017-04-10T12:36:36.544710+00:00 app[web.1]: > node server.js
2017-04-10T12:36:36.544711+00:00 app[web.1]:
2017-04-10T12:36:37.082619+00:00 app[web.1]: App listening on port 8080
2017-04-10T12:37:33.784488+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2017-04-10T12:37:33.760270+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-04-10T12:37:33.760270+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-04-10T12:37:33.878656+00:00 heroku[web.1]: Process exited with status 22
2017-04-10T12:37:33.889982+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T12:37:34.773926+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dry-retreat-69141.herokuapp.com request_id=6ba08c4e-a269-4530-b0db-192da56e2724 fwd="193.1.57.4" dyno= connect= service= status=503 bytes= protocol=https

作为引用,这是我的 server.js 文件

// Set up
var express = require('express');
var app = express(); // create our app w/ express
var mongoose = require('mongoose'); // mongoose for mongodb
var morgan = require('morgan'); // log requests to the console (express4)
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var methodOverride = require('method-override'); // simulate DELETE and PUT (express4)
var cors = require('cors');

// Configuration
//mongoose.connect('mongodb://localhost/reviewking');
mongoose.connect('Connecting to mLabs here URI not included for security reasons');

app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use(methodOverride());
app.use(cors());
app.use(express.static("www")); // Our Ionic app build is in the www folder (kept up-to-date by the Ionic CLI using 'ionic serve')

app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'DELETE, PUT');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

// Models
var Review = mongoose.model('Review', {
title: String,
description: String,
rating: Number
});

// Routes

// Get reviews
app.get('/api/reviews', function(req, res) {

console.log("fetching reviews");

// use mongoose to get all reviews in the database
Review.find(function(err, reviews) {

// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
res.send(err)

res.json(reviews); // return all reviews in JSON format
});
});

// create review and send back all reviews after creation
app.post('/api/reviews', function(req, res) {

console.log("creating review");

// create a review, information comes from request from Ionic
Review.create({
title : req.body.title,
description : req.body.description,
rating: req.body.rating,
done : false
}, function(err, review) {
if (err)
res.send(err);

// get and return all the reviews after you create another
Review.find(function(err, reviews) {
if (err)
res.send(err)
res.json(reviews);
});
});

});

// delete a review
app.delete('/api/reviews/:review_id', function(req, res) {
Review.remove({
_id : req.params.review_id
}, function(err, review) {

});
});


// listen (start app with node server.js) ======================================
app.listen(8080);
console.log("App listening on port 8080");

这是我的 package.json 文件。

{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"start": "node server.js"
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/storage": "1.1.7",
"@types/cordova-plugin-network-information": "0.0.3",
"angularfire2": "^2.0.0-beta.6",
"firebase": "^3.3.0",
"ionic-angular": "2.1.0",
"ionic-native": "2.4.1",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"sw-toolbox": "3.4.0",
"zone.js": "0.6.26",
"@ionic/app-scripts": "1.1.3",
"typescript": "2.0.9",
"mongoose": "^4.6.2",
"body-parser": "^1.15.2",
"cors": "^2.8.0",
"del": "2.2.0",
"express": "^4.14.0",
"http": "0.0.0",
"method-override": "^2.3.6",
"morgan": "^1.7.0",
"superlogin": "^0.6.1"
},
"devDependencies": {
"@ionic/app-scripts": "1.1.3",
"typescript": "2.0.9",
"mongoose": "^4.6.2",
"body-parser": "^1.15.2",
"cors": "^2.8.0",
"del": "2.2.0",
"express": "^4.14.0",
"http": "0.0.0",
"method-override": "^2.3.6",
"morgan": "^1.7.0",
"superlogin": "^0.6.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "ReviewApp: An Ionic project"
}

任何有关此错误的帮助或解决此问题的解决方案(以便我可以将工作应用程序推送到 Heroku)都会有很大帮助。

最佳答案

devDependencies 中删除 mongoose 应该可以修复它。

说明:mongoose 在 package.json 中列出两次 - 一次在 dependency 中,一次在 devDependency 中,但 Heroku 不会安装它们。

我还建议您按字母顺序排列这些依赖项列表,以便将来更容易发现此类问题。

关于node.js - 使用 mongoose 在 Heroku 上托管 Express 应用程序时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43323743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com