All developers know the feeling. You finally figured out how to get that tricky, confusing feature to work properly. You installed all of the necessary dependencies, you made sure all of the packages were on the right version, and you finally ran a successful build that was error-free.
You (hopefully) commit it to the repository at that point and then take a break. You go have a snack and play with the dog in the backyard. 3-4 hours later, you come back to add a couple more lines of code before bed, but when you run the build, you all of the sudden have an error in the command line. This seems to happen all the time with Node.js programs, and it can be very frustrating. My goal here is to provide some positive mental reinforcement, along with some helpful tips that might point you in the right direction in overcoming these errors!
Mental Shifts
Here are some helpful mental frameworks to keep you in the right state of mind while troubleshooting build errors.
1. You have already accomplished a ton with your latest build.
Even if this troubleshooting is the last thing you do today, you have had a productive day of work.
2. This time is well-spent.
You are finding a solution to future build problems as well so you don’t have to use up this duration next time there are similar errors.
3. This is part of the process, embrace it!
The best programmers are the most elite problem solvers. We do not always know the answers, but we are expected to figure it out. The ones who are the best at always figuring it out are undoubtedly the most desirable and most hirable coders in the field!
Actionable Tips
1. Clear out any build caches.
Often times, you can clear out old caches that are kept in Node. For example, if you are building an Expo app you can run expo start -c to clear out the cache from old runs. Sometimes the old builds will have out-of-date dependencies that cause issues.
2. Delete Node_modules and package.json, and reinstall
This tends to ensure that you have the exact packages that you think you do in your package.json. Sometimes when we go down rabbit holes, we start deleting things and altering code, and it can be hard to keep track of.
3. Make frequent commits
This is always a good practice. The more commits you make, the more opportunities you have to revert back if you make too many changes and can’t keep track of what you have done. The more development versions, the better!
Conclusion
Hopefully, this article can help you next time you feel like you are spinning your wheels when troubleshooting. Always remember that your teammates, colleagues, and fellow coders across the world are here to help and support you!