Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heroku crashing due to missing dependency #31

Open
oliverjam opened this issue May 26, 2022 · 0 comments
Open

Heroku crashing due to missing dependency #31

oliverjam opened this issue May 26, 2022 · 0 comments

Comments

@oliverjam
Copy link

oliverjam commented May 26, 2022

(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 dependenciesdevDependencies 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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant