[FAIL] VS Code auto-import breaking the build
I learned about the idea of being a señor engineer and publishing your fails during your work from Kenneth Larsen a few years ago.
I really liked the idea but haven't had a single fail since then 😂 so you guys had to wait for the first of the series until today. I was nudged to do this by Kenneth's recent tweet:
The fail
I was working on an Ember application and the (re-)build suddenly started failing with a not very descriptive error message. Although far from being usual, this wasn't the first time, so I restarted the build process.
It failed again so I removed node_modules
and reinstalled all the dependencies which made the build fail with another error message.
This new one was vaguely familiar, the installation of node-gyp
complaining about not finding XCode and then erroring out on a python expression. After some digging around, and running yarn why node-gyp
to learn which direct dependency causes node-gyp
to be installed, I updated that dependency. Luckily, the bug seems to have been fixed in the newer one.
I was crossing my fingers to see if the original error has been overcome but to my chagrin it was still there. I took another hour or more trying to clean caches, and upgrade a scientifically chosen set of dependencies but nothing worked.
I decided to call it a day and have something for dinner. When I went to bed and prepared to sleep, my mind spoke: "You know full well what it is, don't you? It's one of those random import statements VSCode inserts when you're not looking." God, you're right, I told my mind and sank into sweet dreams.
The next day, I checked the last commit and lo and behold, one of the front-end module files had an import e from 'express'
that I definitely didn't mean to add. Removing it made the build behave again.
What are the takeaways?
- Always check what you did last before the problem appeared. It was harder to do here as I didn't deliberately add the faulty line but I could've checked the diff.
- Trust your subconscious. This has happened to me countless times during my career and I still forget about it: if you're close to finishing up for the day, just do it. Your mind will keep working on the problem in the background which also frees up your foreground, blocking mind process to do something useful or entertaining. Fancy a game of chess?
- Step away from the computer. It's very easy to get sucked into trying to clean caches, reinstall dependencies and search for people having the same problem in Github repositories. Sometimes, that is actually the way to redemption but it's always a good idea to take breaks regularly and not consciously think of the problem. I think it's better to down your tools for the day, if you can, but sometimes you can't – go for a walk, chat with somebody, or take a nap.
- Turn off that ridiculous auto-import in VSCode. Unfortunately, I don't know how to do that, so please tell!