App Working Locally but getting error while I upload to heroku

Hi everyone

I have fought hard to resolve this error. My app works well locally however after uploading to heroku I try to open the app and it says application error. I tried to follow what I think the error is saying checked the models/Idea but nothing is wrong with it. Below is what my log says PLEASE Kindly let me know what could possibly be wrong.

Starting process with command `npm start`

2019-04-19T17:56:05.281682+00:00 app[web.1]:

2019-04-19T17:56:05.281701+00:00 app[web.1]: > protegee@1.0.0 start /app

2019-04-19T17:56:05.281703+00:00 app[web.1]: > node app.js

2019-04-19T17:56:05.281705+00:00 app[web.1]:

2019-04-19T17:56:06.169728+00:00 app[web.1]: internal/modules/cjs/loader.js:584

2019-04-19T17:56:06.169759+00:00 app[web.1]: throw err;

2019-04-19T17:56:06.169760+00:00 app[web.1]: ^

2019-04-19T17:56:06.169762+00:00 app[web.1]:

2019-04-19T17:56:06.169764+00:00 app[web.1]: Error: Cannot find module '../models/Idea'

2019-04-19T17:56:06.169766+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)2019-04-19T17:56:06.169768+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)

2019-04-19T17:56:06.169770+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:06.169772+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:06.169773+00:00 app[web.1]: at Object.<anonymous> (/app/routes/ideas.js:7:1)

2019-04-19T17:56:06.169775+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:06.169776+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:06.169778+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:06.169779+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

2019-04-19T17:56:06.169781+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)

2019-04-19T17:56:06.169782+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:06.169784+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:06.169785+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:15:15)

2019-04-19T17:56:06.169787+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:06.169788+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:06.169790+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:06.187204+00:00 app[web.1]: npm ERR! code ELIFECYCLE

2019-04-19T17:56:06.187681+00:00 app[web.1]: npm ERR! errno 1

2019-04-19T17:56:06.188845+00:00 app[web.1]: npm ERR! protegee@1.0.0 start: `node app.js`

2019-04-19T17:56:06.189010+00:00 app[web.1]: npm ERR! Exit status 1

2019-04-19T17:56:06.189269+00:00 app[web.1]: npm ERR!

2019-04-19T17:56:06.189444+00:00 app[web.1]: npm ERR! Failed at the protegee@1.0.0 start script.

2019-04-19T17:56:06.189629+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2019-04-19T17:56:06.198753+00:00 app[web.1]:

2019-04-19T17:56:06.198985+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:

2019-04-19T17:56:06.199117+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-04-19T17_56_06_191Z-debug.log

2019-04-19T17:56:06.294335+00:00 heroku[web.1]: State changed from starting to crashed

2019-04-19T17:56:06.299680+00:00 heroku[web.1]: State changed from crashed to starting

2019-04-19T17:56:06.271809+00:00 heroku[web.1]: Process exited with status 1

2019-04-19T17:56:13.091385+00:00 heroku[web.1]: Starting process with command `npm start`

2019-04-19T17:56:15.873008+00:00 app[web.1]:

2019-04-19T17:56:15.873036+00:00 app[web.1]: > protegee@1.0.0 start /app

2019-04-19T17:56:15.873038+00:00 app[web.1]: > node app.js

2019-04-19T17:56:15.873039+00:00 app[web.1]:

2019-04-19T17:56:16.616624+00:00 app[web.1]: internal/modules/cjs/loader.js:584

2019-04-19T17:56:16.616667+00:00 app[web.1]: throw err;

2019-04-19T17:56:16.616669+00:00 app[web.1]: ^

2019-04-19T17:56:16.616671+00:00 app[web.1]:

2019-04-19T17:56:16.616672+00:00 app[web.1]: Error: Cannot find module '../models/Idea'

2019-04-19T17:56:16.616676+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)2019-04-19T17:56:16.616677+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)

2019-04-19T17:56:16.616679+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:16.616681+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:16.616682+00:00 app[web.1]: at Object.<anonymous> (/app/routes/ideas.js:7:1)

2019-04-19T17:56:16.616684+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:16.616686+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:16.616687+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:16.616689+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

2019-04-19T17:56:16.616690+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)

2019-04-19T17:56:16.616692+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:16.616694+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:16.616695+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:15:15)

2019-04-19T17:56:16.616697+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:16.616698+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:16.616700+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:16.631621+00:00 app[web.1]: npm ERR! code ELIFECYCLE

2019-04-19T17:56:16.631773+00:00 app[web.1]: npm ERR! errno 1

2019-04-19T17:56:16.633399+00:00 app[web.1]: npm ERR! protegee@1.0.0 start: `node app.js`

2019-04-19T17:56:16.633580+00:00 app[web.1]: npm ERR! Exit status 1

2019-04-19T17:56:16.633801+00:00 app[web.1]: npm ERR!

2019-04-19T17:56:16.633914+00:00 app[web.1]: npm ERR! Failed at the protegee@1.0.0 start script.

2019-04-19T17:56:16.634013+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-19T17:56:16.645475+00:00 app[web.1]:
2019-04-19T17:56:16.645736+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-19T17:56:16.645880+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-04-19T17_56_16_636Z-debug.log
2019-04-19T17:56:16.752779+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-19T17:56:16.729341+00:00 heroku[web.1]: Process exited with status 1
2019-04-19T17:57:09.597846+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=[boiling-lowlands-12854.herokuapp.com]   request_id=303de59c-ddea-475a-8e8b-acb6616755d4 fwd="108.24.111.88" dyno= connect= service= status=503 bytes= protocol=https
2019-04-19T17:57:09.943659+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=[boiling-lowlands-12854.herokuapp.com] request_id=9c58bad6-5808-48c4-8faf-00eee5ab9688 fwd="108.24.111.88" dyno= connect= service= status=503 bytes= protocol=https
[details="Summary"]
This text will be hidden
[/details]

[details="Summary"]
This text will be hidden
[details="Summary"]
This text will be hidden
[/details]

[/details]

Hi Brad,

I have fought hard to resolve this error. My app works well locally however after uploading to heroku I try to open the app and it says application error. I tried to follow what I think the error is saying checked the models/Idea but nothing is wrong with it.  Below is what my log says PLEASE Kindly let me know what could possibly be wrong.

Starting process with command npm start

2019-04-19T17:56:05.281682+00:00 app[web.1]:

2019-04-19T17:56:05.281701+00:00 app[web.1]: > protegee@1.0.0 start /app

2019-04-19T17:56:05.281703+00:00 app[web.1]: > node app.js

2019-04-19T17:56:05.281705+00:00 app[web.1]:

2019-04-19T17:56:06.169728+00:00 app[web.1]: internal/modules/cjs/loader.js:584

2019-04-19T17:56:06.169759+00:00 app[web.1]: throw err;

2019-04-19T17:56:06.169760+00:00 app[web.1]: ^

2019-04-19T17:56:06.169762+00:00 app[web.1]:

2019-04-19T17:56:06.169764+00:00 app[web.1]: Error: Cannot find module ‘…/models/Idea’

2019-04-19T17:56:06.169766+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)2019-04-19T17:56:06.169768+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)

2019-04-19T17:56:06.169770+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:06.169772+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:06.169773+00:00 app[web.1]: at Object. (/app/routes/ideas.js:7:1)

2019-04-19T17:56:06.169775+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:06.169776+00:00 app[web.1]: at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:06.169778+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:06.169779+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

2019-04-19T17:56:06.169781+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)

2019-04-19T17:56:06.169782+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:06.169784+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:06.169785+00:00 app[web.1]: at Object. (/app/app.js:15:15)

2019-04-19T17:56:06.169787+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:06.169788+00:00 app[web.1]: at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:06.169790+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:06.187204+00:00 app[web.1]: npm ERR! code ELIFECYCLE

2019-04-19T17:56:06.187681+00:00 app[web.1]: npm ERR! errno 1

2019-04-19T17:56:06.188845+00:00 app[web.1]: npm ERR! protegee@1.0.0 start: node app.js

2019-04-19T17:56:06.189010+00:00 app[web.1]: npm ERR! Exit status 1

2019-04-19T17:56:06.189269+00:00 app[web.1]: npm ERR!

2019-04-19T17:56:06.189444+00:00 app[web.1]: npm ERR! Failed at the protegee@1.0.0 start script.

2019-04-19T17:56:06.189629+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2019-04-19T17:56:06.198753+00:00 app[web.1]:

2019-04-19T17:56:06.198985+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:

2019-04-19T17:56:06.199117+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-04-19T17_56_06_191Z-debug.log

2019-04-19T17:56:06.294335+00:00 heroku[web.1]: State changed from starting to crashed

2019-04-19T17:56:06.299680+00:00 heroku[web.1]: State changed from crashed to starting

2019-04-19T17:56:06.271809+00:00 heroku[web.1]: Process exited with status 1

2019-04-19T17:56:13.091385+00:00 heroku[web.1]: Starting process with command npm start

2019-04-19T17:56:15.873008+00:00 app[web.1]:

2019-04-19T17:56:15.873036+00:00 app[web.1]: > protegee@1.0.0 start /app

2019-04-19T17:56:15.873038+00:00 app[web.1]: > node app.js

2019-04-19T17:56:15.873039+00:00 app[web.1]:

2019-04-19T17:56:16.616624+00:00 app[web.1]: internal/modules/cjs/loader.js:584

2019-04-19T17:56:16.616667+00:00 app[web.1]: throw err;

2019-04-19T17:56:16.616669+00:00 app[web.1]: ^

2019-04-19T17:56:16.616671+00:00 app[web.1]:

2019-04-19T17:56:16.616672+00:00 app[web.1]: Error: Cannot find module ‘…/models/Idea’

2019-04-19T17:56:16.616676+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)2019-04-19T17:56:16.616677+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:508:25)

2019-04-19T17:56:16.616679+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:16.616681+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:16.616682+00:00 app[web.1]: at Object. (/app/routes/ideas.js:7:1)

2019-04-19T17:56:16.616684+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:16.616686+00:00 app[web.1]: at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:16.616687+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:16.616689+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:539:12)

2019-04-19T17:56:16.616690+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:531:3)

2019-04-19T17:56:16.616692+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:637:17)

2019-04-19T17:56:16.616694+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:22:18)

2019-04-19T17:56:16.616695+00:00 app[web.1]: at Object. (/app/app.js:15:15)

2019-04-19T17:56:16.616697+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:701:30)

2019-04-19T17:56:16.616698+00:00 app[web.1]: at Object.Module._extensions…js (internal/modules/cjs/loader.js:712:10)

2019-04-19T17:56:16.616700+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:600:32)

2019-04-19T17:56:16.631621+00:00 app[web.1]: npm ERR! code ELIFECYCLE

2019-04-19T17:56:16.631773+00:00 app[web.1]: npm ERR! errno 1

2019-04-19T17:56:16.633399+00:00 app[web.1]: npm ERR! protegee@1.0.0 start: node app.js

2019-04-19T17:56:16.633580+00:00 app[web.1]: npm ERR! Exit status 1

2019-04-19T17:56:16.633801+00:00 app[web.1]: npm ERR!

2019-04-19T17:56:16.633914+00:00 app[web.1]: npm ERR! Failed at the protegee@1.0.0 start script.

2019-04-19T17:56:16.634013+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-19T17:56:16.645475+00:00 app[web.1]:
2019-04-19T17:56:16.645736+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-19T17:56:16.645880+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-04-19T17_56_16_636Z-debug.log
2019-04-19T17:56:16.752779+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-19T17:56:16.729341+00:00 heroku[web.1]: Process exited with status 1
2019-04-19T17:57:09.597846+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/"  request_id=303de59c-ddea-475a-8e8b-acb6616755d4 fwd=“108.24.111.88” dyno= connect= service= status=503 bytes= protocol=https
2019-04-19T17:57:09.943659+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/favicon.ico" request_id=9c58bad6-5808-48c4-8faf-00eee5ab9688 fwd=“108.24.111.88” dyno= connect= service= status=503 bytes= protocol=https

Have you looked at the files (line numbers) indicated in the errors being thrown? You did not provide a link to your project files, so you will need to investigate further.

Oh sorry i have it on my github page. https://github.com/holarmyde/Protegee.git . I have looked at the files (models/Idea, app.js)that was indicated in the error however nothing seems to be wrong with them.

Is it by chance because your idea.js is lowercase? The error is referencing Idea - uppercase.
Might be this line in your routes/ideas.js:
require("../models/Idea");

idea.js in my route folder is different from the Idea.js in my models folder. require("…/models/Idea") is not the problem I checked it.

I think you need to export your models:

module.exports = mongoose.model("ideas", IdeaSchema)

And do the same for your User model.

Thanks Jack I did just what you said for both the Idea and user models however this time it brings a new set of errors. module.exports = mongoose.model(“ideas”, IdeaSchema) wouldnt make it connect to the database thats why i didnt use the module.exports function.

/app/node_modules/mongoose/lib/connection.js:465
2019-04-25T21:09:38.617664+00:00 app[web.1]: throw new MongooseError('The uri parameter to openUri() must be a ’ +
2019-04-25T21:09:38.617666+00:00 app[web.1]: ^
2019-04-25T21:09:38.618061+00:00 app[web.1]: MongooseError: The uri parameter to openUri() must be a string, got “undefined”. Make sure the first parameter to mongoose.connect() or mongoose.createConnection() is a string.
2019-04-25T21:09:38.618064+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-25T21:09:38.618066+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-25T21:09:38.618068+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)

Hmm, I just noticed you said this works locally but not on Heroku.

Have you checked that you’ve set your environment variables correctly via your Heroku dashboard?

You could also try console logging the mongoUri from Heroku to check that it is pointing at the right mlab database, or is correctly formed.

2 Likes

Jack you are a genius mehn. It worked. . You were right I didnt set my environment variables at all via my Heroku dashboard. Thanks a lot

2 Likes