I was finally able to deploy my application to Heroku, but there’s a new problem. When I try to view the app I get a page that says “Application Error”. When I open the heroku logs, it says “Cannot find module dotenv”.
But I do have dotenv in my package.json and my package-lock.json
I figured the problem was that dotenv was listed as a devDependency so I tried npm i dotenv and even npm i -D dotenv. I also made sure to restart VSC afterwards, but nothing seems to be getting rid of the error.
Some of the other forums suggested we restart our code editors once we retry installing dotenv. Redeploying hasn’t worked out yet.
As for putting dotenv in the dependency section; should I just copy paste it from dev dependencies, then hit npm install? I tried doing npm install dotenv to begin with, but it didn’t work
Either should work. You can do npm i dotenv" or manually edit it and npm i`. The important thing is that you have it in your dependencies and not dev dependencies.
If you want to be extra sure, delete package-lock.json and the node_modules folder before installing. Then you need to push that to heroku.
reinstalling before push … yes and no. It won’t matter for the node_modules because you aren’t pushing them anyway. But it does matter for the lock file - that gets pushed and is important so it knows exactly which version to use for consistency. So, yes, install before push.