You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(I can't see your server logs so I don't know for sure)
I think your Heroku server is crashing because you have dotenv listed as a devDependency in your package.json, but you import and use the dotenv library in your server.js file. When Heroku runs your code in that file it tries to import a package that isn't installed, and throws an error.
Heroku does not install devDependencies in production (since they aren't needed). If you are going to use a library in your code it needs to be in your actual dependencies—devDependencies is for things that are only used locally.
In this case you don't actually needdotenv in production, since it is only used to load your local .env file during local development. In production Heroku provides all the environment variables (there is no .env file). You've already configured your dev npm script to run nodemon -r dotenv/config, which means your local server will have the .env file loaded.
You can fix this by just removing any references to require("dotenv") or dotenv.config() from your code.
The text was updated successfully, but these errors were encountered:
(I can't see your server logs so I don't know for sure)
I think your Heroku server is crashing because you have
dotenv
listed as adevDependency
in yourpackage.json
, but you import and use the dotenv library in yourserver.js
file. When Heroku runs your code in that file it tries to import a package that isn't installed, and throws an error.Heroku does not install devDependencies in production (since they aren't needed). If you are going to use a library in your code it needs to be in your actual
dependencies
—devDependencies
is for things that are only used locally.In this case you don't actually need
dotenv
in production, since it is only used to load your local.env
file during local development. In production Heroku provides all the environment variables (there is no.env
file). You've already configured yourdev
npm script to runnodemon -r dotenv/config
, which means your local server will have the.env
file loaded.You can fix this by just removing any references to
require("dotenv")
ordotenv.config()
from your code.The text was updated successfully, but these errors were encountered: