When I run heroku local
or when I just do npm start
locally, my app builds and runs fine. However when I deploy to heroku, the app crashes saying it ca
Specifically, include the necessary dependency under 'dependencies' and not 'devDependencies' in your 'package.json file'. This is because Heroku prunes (removes) your 'devDependencies' once it completes its build process, leaving only the 'dependencies', to keep the app as lean as possible.
This causes errors if you've built your NodeJS app using ES6 modules and included the necessary dependencies under 'devDependencies' instead of 'dependencies', namely the '@babel/' family of dependencies.
Update
You should always build your NodeJS App before you deploy it so that you are always running the production build in the live environment which executes much faster with fewer resources.