I've been doing a lot lately with Grunt and LibSass within my drupal.org contrib theme, Gratis. Yesterday, I updated my Node modules locally. Shortly thereafter, I started getting a nasty Drush error.
or sometimes just:
Not only that but my local site's admin UI started WSODing. I didn't immediately connect the Node NPM update to the drush error. So I looked in my MacPorts Apache log and saw hundreds of these streaming down every few seconds:
Doing a Google search led me to some varied and vague issues with regard to Apache and MySQL but none of theme really rang true to what I was experiencing. I decided to check some of my other local sites and they all seemed fine; no errors, WSODs, or otherwise. Bizarre! I worked for about an hour, but still no joy, I was headed down a rabbit hole. That being said, I let this rest for a while. I always let a problem sit for a bit if I can't fix it right away or ask for help. More often than not, I'll come back later and end up fixing it.
I got out for some air and went to downtown San Diego to take some photos. That usually gets my mind off things and is relaxing. Arriving back later in the day, I got back into it and decided to search for drush cache clear segmentation fault theme. Bingo! (and 50 browser tabs later). I don't know why I didn't search for this earlier in the day, I was just searching the pure Apache log error which knows nothing of drush.
Sure enough it's an error related to Node modules (from the node_modules folder) having a .info file. Drush sees that and thinks it's supposed to be part of Drupal. The problem is, in a Drush world, these files are malformed. Thus the errors. Right about now, I was wishing there was some kind of .drushignore file along the same lines as .gitignore.
With this new search, here's the relevant posts I found:
- Clearing Cache with Browser-sync 1.3.0 Results in a Segment Fault: 11 error
- How do I prevent Drupal raising a segmentation fault when using a Node.js theming workflow?
In turn, these led me to the main issue, Themes should not crash when .info file appears inside node_modules
It turns out there is a proposed patch for core to prevent this error. I somehow don't see this getting in anytime soon but there are some workarounds on the Node / Grunt end of things.
Here is the fix that I arrived at based on all the suggestions and comments in this last issue.
First, we need to write a Node NPM cleanup Bash script. The script will find any .info files and rename them
to .inf0 (with a zero). This will not have any negative effects as you don't commit node_modules
folder to your repo and the info files are not actually needed for Grunt to run properly. So we'll call our script,
Once you have this in the same folder as your package.json file (in my case the root of my theme), you'll need to call it with a
postinstall method from your package.json file.
One caveat here is that you may run into an error that the script won't run.
To solve this you can either run
sudo npm install --unsafe-perm
or alternatively create an .npmrc file with the code:
and then run
sudo npm install as usual.
Running into errors like this is definitely not fun but I learned a lot in the process. I am not sure if this is the best fix in the world but it seems to work fine for my use case. It also shows us to not get tunnel vision when trying to fix a development problem and to avoid those rabbit holes if possible.