I'm trying to deploy my application on Heroku and it gives me an 'Application error', I had already deployed it without problems before and it worked fine, I started to add some more things, create an api, add POST's and GET's, I pushed it again and it stopped to function. It gives me this error when opening my application in heroku, it is worth mentioning that locally it works fine, even using ngrok from Vs.
Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail
When viewing the logs from heroku it tells me this:
2021-02-18T14:28:25.869957+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=chatbotlaboratorio.herokuapp.com
request_id=a189272f-353d-4015-b7c7-ccfffd4d5e43 fwd="187.228.67.38" dyno=
connect= service= status=503 bytes= protocol=https
2021-02-18T14:28:26.080311+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=chatbotlaboratorio.herokuapp.com
request_id=4fdfaba7-9df2-4629-86c2-63df53a6185e fwd="187.228.67.38" dyno=
connect= service= status=503 bytes= protocol=https
2021-02-18T14:36:01.159267+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/robots.txt" host=chatbotlaboratorio.herokuapp.com
request_id=5794baee-2ada-4b3b-a1c8-2704c1a5ca88 fwd="94.130.167.103" dyno=
connect= service= status=503 bytes= protocol=http
2021-02-18T14:36:01.366649+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=chatbotlaboratorio.herokuapp.com
request_id=87bc0bb7-ce64-4df1-9e9a-f4901698eaa8 fwd="94.130.167.103" dyno=
connect= service= status=503 bytes= protocol=http
2021-02-18T14:41:14.391693+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=chatbotlaboratorio.herokuapp.com
request_id=65463729-4be1-4d79-9d6c-3ebfbd1da7f0 fwd="187.228.67.38" dyno=
connect= service= status=503 bytes= protocol=https
2021-02-18T14:41:14.659036+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=chatbotlaboratorio.herokuapp.com
request_id=68a27808-7b8c-4436-9a60-2becf4e18448 fwd="187.228.67.38" dyno=
connect= service= status=503 bytes= protocol=https
2021-02-18T14:41:58.578306+00:00 heroku[web.1]: State changed from crashed to
starting
2021-02-18T14:42:03.075789+00:00 heroku[web.1]: Starting process with command
`npm start`
2021-02-18T14:42:06.460302+00:00 app[web.1]:
2021-02-18T14:42:06.460321+00:00 app[web.1]: > [email protected] start /app
2021-02-18T14:42:06.460321+00:00 app[web.1]: > node server.js
2021-02-18T14:42:06.460322+00:00 app[web.1]:
2021-02-18T14:42:07.488076+00:00 app[web.1]:
internal/modules/cjs/loader.js:883
2021-02-18T14:42:07.488099+00:00 app[web.1]: throw err;
2021-02-18T14:42:07.488100+00:00 app[web.1]: ^
2021-02-18T14:42:07.488100+00:00 app[web.1]:
2021-02-18T14:42:07.488102+00:00 app[web.1]: Error: Cannot find module
'../chatbotDialogflowNodejs/config'
2021-02-18T14:42:07.488102+00:00 app[web.1]: Require stack:
2021-02-18T14:42:07.488103+00:00 app[web.1]: - /app/server.js
2021-02-18T14:42:07.488105+00:00 app[web.1]: at
Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
2021-02-18T14:42:07.488105+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:725:27)
2021-02-18T14:42:07.488105+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:952:19)
2021-02-18T14:42:07.488106+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:88:18)
2021-02-18T14:42:07.488106+00:00 app[web.1]: at Object.<anonymous>
(/app/server.js:5:16)
2021-02-18T14:42:07.488107+00:00 app[web.1]: at Module._compile
(internal/modules/cjs/loader.js:1063:30)
2021-02-18T14:42:07.488107+00:00 app[web.1]: at
Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-02-18T14:42:07.488107+00:00 app[web.1]: at Module.load
(internal/modules/cjs/loader.js:928:32)
2021-02-18T14:42:07.488108+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:769:14)
2021-02-18T14:42:07.488109+00:00 app[web.1]: at
Function.executeUserEntryPoint [as runMain]
(internal/modules/run_main.js:72:12)
2021-02-18T14:42:07.488109+00:00 app[web.1]: at
internal/main/run_main_module.js:17:47 {
2021-02-18T14:42:07.488109+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-02-18T14:42:07.488110+00:00 app[web.1]: requireStack: [
'/app/server.js' ]
2021-02-18T14:42:07.488110+00:00 app[web.1]: }
2021-02-18T14:42:07.518235+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-02-18T14:42:07.518886+00:00 app[web.1]: npm ERR! errno 1
2021-02-18T14:42:07.530496+00:00 app[web.1]: npm ERR! [email protected]
start: `node server.js`
2021-02-18T14:42:07.530760+00:00 app[web.1]: npm ERR! Exit status 1
2021-02-18T14:42:07.531075+00:00 app[web.1]: npm ERR!
2021-02-18T14:42:07.531340+00:00 app[web.1]: npm ERR! Failed at the
[email protected] start script.
2021-02-18T14:42:07.531573+00:00 app[web.1]: npm ERR! This is probably not a
problem with npm. There is likely additional logging output above.
2021-02-18T14:42:07.542523+00:00 app[web.1]:
2021-02-18T14:42:07.542855+00:00 app[web.1]: npm ERR! A complete log of this
run can be found in:
2021-02-18T14:42:07.543029+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2021-02-18T14_42_07_532Z-debug.log
2021-02-18T14:42:07.608653+00:00 heroku[web.1]: Process exited with status 1
2021-02-18T14:42:07.676122+00:00 heroku[web.1]: State changed from starting
to crashed
2021-02-18T14:42:07.684683+00:00 heroku[web.1]: State changed from crashed to
starting
2021-02-18T14:42:11.825694+00:00 heroku[web.1]: Starting process with command
`npm start`
2021-02-18T14:42:14.925472+00:00 app[web.1]:
2021-02-18T14:42:14.925644+00:00 app[web.1]: > [email protected] start /app
2021-02-18T14:42:14.925645+00:00 app[web.1]: > node server.js
2021-02-18T14:42:14.925650+00:00 app[web.1]:
2021-02-18T14:42:15.679796+00:00 app[web.1]:
internal/modules/cjs/loader.js:883
2021-02-18T14:42:15.679842+00:00 app[web.1]: throw err;
2021-02-18T14:42:15.679842+00:00 app[web.1]: ^
2021-02-18T14:42:15.679843+00:00 app[web.1]:
2021-02-18T14:42:15.679843+00:00 app[web.1]: Error: Cannot find module
'../chatbotDialogflowNodejs/config'
2021-02-18T14:42:15.679844+00:00 app[web.1]: Require stack:
2021-02-18T14:42:15.679844+00:00 app[web.1]: - /app/server.js
2021-02-18T14:42:15.679845+00:00 app[web.1]: at
Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
2021-02-18T14:42:15.679845+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:725:27)
2021-02-18T14:42:15.679846+00:00 app[web.1]: at Module.require
(internal/modules/cjs/loader.js:952:19)
2021-02-18T14:42:15.679846+00:00 app[web.1]: at require
(internal/modules/cjs/helpers.js:88:18)
2021-02-18T14:42:15.679847+00:00 app[web.1]: at Object.<anonymous>
(/app/server.js:5:16)
2021-02-18T14:42:15.679847+00:00 app[web.1]: at Module._compile
(internal/modules/cjs/loader.js:1063:30)
2021-02-18T14:42:15.679847+00:00 app[web.1]: at
Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-02-18T14:42:15.679848+00:00 app[web.1]: at Module.load
(internal/modules/cjs/loader.js:928:32)
2021-02-18T14:42:15.679848+00:00 app[web.1]: at Function.Module._load
(internal/modules/cjs/loader.js:769:14)
2021-02-18T14:42:15.679849+00:00 app[web.1]: at
Function.executeUserEntryPoint [as runMain]
(internal/modules/run_main.js:72:12)
2021-02-18T14:42:15.679850+00:00 app[web.1]: at
internal/main/run_main_module.js:17:47 {
2021-02-18T14:42:15.679850+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-02-18T14:42:15.679850+00:00 app[web.1]: requireStack: [
'/app/server.js' ]
2021-02-18T14:42:15.679851+00:00 app[web.1]: }
2021-02-18T14:42:15.697511+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-02-18T14:42:15.698033+00:00 app[web.1]: npm ERR! errno 1
2021-02-18T14:42:15.706610+00:00 app[web.1]: npm ERR! [email protected]
start: `node server.js`
2021-02-18T14:42:15.706919+00:00 app[web.1]: npm ERR! Exit status 1
2021-02-18T14:42:15.707107+00:00 app[web.1]: npm ERR!
2021-02-18T14:42:15.707250+00:00 app[web.1]: npm ERR! Failed at the
[email protected] start script.
2021-02-18T14:42:15.707371+00:00 app[web.1]: npm ERR! This is probably not a
problem with npm. There is likely additional logging output above.
2021-02-18T14:42:15.716447+00:00 app[web.1]:
2021-02-18T14:42:15.716824+00:00 app[web.1]: npm ERR! A complete log of this
run can be found in:
2021-02-18T14:42:15.717002+00:00 app[web.1]: npm ERR!
/app/.npm/_logs/2021-02-18T14_42_15_708Z-debug.log
2021-02-18T14:42:15.790661+00:00 heroku[web.1]: Process exited with status 1
2021-02-18T14:42:15.939560+00:00 heroku[web.1]: State changed from starting
to crashed
Herou nodejs version 14.15.5 and local 14.15.4
The code of my server.js file in my webhook is the following:
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const mongoose = require('mongoose');
const config = require("../chatbotDialogflowNodejs/config");
const port = process.env.PORT || 3000;
// for parsing json
app.use(
bodyParser.json({
limit: "20mb",
})
);
// parse application/x-www-form-urlencoded
app.use(
bodyParser.urlencoded({
extended: false,
limit: "20mb",
})
);
mongoose.connect(
config.MONGODB, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
}, (err, res) => {
if (err) return console.log("Hubo un error en la BD ", err);
console.log("BD online");
}
);
app.use("/messenger", require("./Facebook/facebookBot"));
//Siempre las rutas dentro del archivo api empezaran con /api/
app.use("/api", require("./routes/api"));
app.get("/", (req, res) => {
return res.send("Chatbot Funcionando ???");
});
app.listen(port, () => {
console.log(`Escuchando peticiones en el puerto ${port}`);
});
I hope someone can help me, thank you very much!
If it helps anyone in the future, what worked for me was to remove the part in the code above the server.js file that says "config.MONGODB" in the mongoose connection since it was taking that string from the config file .js in the wrong way, I just had to write "MONGODB" (as the variable is called in config), I did git add , commit and push again and that's it. Note: this way doesn't work locally, so what I did was create another branch, one to test locally and another to deploy to heroku.
In the logs it is seen that the error is this: 2021-02-18T14:42:07.488102+00:00 app[web.1]: Error: Cannot find module '../chatbotDialogflowNodejs/config'
possibly there is an error linking the file