allenjd3 a place to set on

Carrots

Coding can be an art form. Many folks get all wrapped up in the elegance of well designed code. It doesn’t take long when diving into a new piece of code to see whether it was well designed and well thought out, or if I coded it. (Only kidding- kind of…) Laravel’s tagline is “The PHP Framework for Web Artisans.” It’s aptly named, if a little pretentious. You can create really beautiful code with laravel. You can create beautiful code with Ruby on Rails, or nodejs. And then there is wordpress.

Don’t get me wrong. Wordpress is the engine behind the web. It drives a large portion of blogs, businesses and ecommerce solutions. It does it quite well also and is fairly user-friendly in the admin panel. The code is ugly though…

Case in point-

<?php 
if ( have_posts() ) : 
while ( have_posts() ) : the_post(); 
    // Display post content
endwhile; 
endif; 
?>

The dreaded “loop”. You have to put this bad boy everywhere. And what is with all of these functions? I guess PHP didn’t have classes when wordpress was built? No wait, I know there were classes because of the “walkers.” No we aren’t talking about the AMC TV show The Walking Dead. These are classes that you have to extend in order to make changes to the html output of navigation or comments. Then there are the inline image styles… Makes me shudder to think about it.

This is the reason I started looking for another solution. That’s when I found roots/sage. This is a theme that uses a lot of the things I love about Laravel and incorporates them into Wordpress development. It lets you do things like this-

@extends('layouts.base')

@section('content')
  @while(have_posts())
  {!! the_post() !!}
  @include('partials/content-single')
@endwhile
@endsection

Ahhh, that’s better… I happily installed it and typed yarn start and wah wah waaahhh. It failed! It tried to build out node-sass but was unable to complete the task. (I’m using version 9 of sage btw, this is fixed in version 10) So I messed around for a long time trying to figure out the issue. I looked at my version of Node. (It was a little old so I updated). Still no-go. I upgraded my version of windows build tools. Nada. I was about to give up until I dug into the node-sass github readme and noticed this little gem-

Supported Nodejs Versions-

Node 14 	4.14+ 	83
Node 13 	4.13+ 	79
Node 12 	4.12+ 	72
Node 11 	4.10+ 	67
Node 10 	4.9+ 	64
Node 8 	4.5.3+ 	57

In the package.json- version 9 is set to ~4.9 and I had node version 14… Tah Dah! I changed the version from ~4.9 to ^4.9 and boom- sweet roots/sage magic commenced. From then on, I danced around in beautiful blade templates and went to sleep dreaming of partials and layout files.

;TLDR If you are trying roots/sage and come across an error about node-sass, you likely aren’t using a supported version of node.