Exercism CLI Setup & Install JavaScript locally: Possible Errors on a Mac
Tags: beginners, debugging, exercism, javascript
Published: 2021-12-14 03:51:04

When working on Exercism exercises, you can either solve the problems using the online editor or working on them locally in your own favorite IDE and submit them through the CLI (Command Line Interface) on terminal. While installing Exercism locally on my MacOS, I have encountered several errors that took me some times to figure them out. 

You may not have encountered the following errors if you have not already had Homebrew or Node installed. 

As found, here are the **causes** of the errors I encountered: 
1. Outdated Homebrew Version 
2. Outdated Node Version 

I am going to generally walk through my debugging process - how I found the issue and how I researched to figure it out. 

If you are comfortable installing exercism via Homebrew, Exercism will give you the following 2 steps:

**Step 1: Install Exercism through Homebrew**  

```
brew update  
brew install exercism 

exercism version --> this is only used for checking the exercism version
```

**Step 2: Configuring the CLI in the terminal**
```
exercism configure --token=[THIS IS THE SECRET TOKEN THAT CANNOT BE SHARED]
```
Once this is completed, you have successfully installed Exercism locally. 

___

## Outdated Homebrew Version

Initially, I got an error when running `brew update`:

```
Error: 
 homebrew-core is a shallow clone.
```
I did not know what is going on until I checked the Homebrew version using `brew --version`, then I found the following error:

```
unknown or unsupported macOS version: :dunno (MacOSVersionError)
```

I did some google searches and found [this stack overflow question](https://stackoverflow.com/questions/64821648/homebrew-fails-on-macos-big-sur) regarding Homebrew failed on a macOS version. As noted in one of the highest votes answer, here is how to update the Homebrew version: 

```
brew update-reset
```
It would take some times to reset. Once it is reset, you can check the version again using `brew --version`. You should see the current version of the Homebrew this time instead of an error log. 

___


## Outdated Node Version  

However, even though I have reset/updated the Homebrew version, when I ran `brew update` again, I still saw the same error: 
 
```
Error: 
 homebrew-core is a shallow clone.
```
I did not know why. I decided to install exercism and configure first and ignore the error. Until when I did `npm install`, I got a lot of warnings on different npm packages outdated or deprecated. I also got an error when running `npm test`: 

```
SyntaxError: Unexpected token
```
After several trials and errors to see if I could do an npm install for each older npm packages, I realized this was a time consuming and ineffective method. It did not really help me to know the actual cause of the issue. 

I decided to ask my friend, Google, and I found this [stack overflow question](https://stackoverflow.com/questions/62968136/unexpected-token-syntaxerror-after-updating-jest-testing-libraries). One of the answer actually tell me the possible cause of the issue could be an **outdated Node version**. 

Using `node --version` to find out the current version I was on. 

Then, using `nvm install [NEW NODE VERSION]` to install the latest version.

(_the version I have in the code snippet below is only the latest one at the moment I am writing this post, in order to check the most recent Node version, click [here](https://nodejs.org/en/)_)

```
nvm install 16.13.1
```
Once these steps are completed, congrats!! You should be able to successfully do `npm install` and `npm test` this time without any more errors!!

___

Thank you for reading through this and hopefully it can help you out if you are encountering similar issues I did.

Below are some additional resources just in case you might find them helpful: 

- [What is Homebrew and How to install](https://brew.sh/)
- [How to update Node.js](https://stackoverflow.com/questions/8191459/how-do-i-update-node-js)
- [How to install JavaScript locally for Exercism exercises](https://exercism.org/docs/tracks/javascript/installation)

Have fun, Exercism-ing Locally! 

___

By the way, if you ever see the following error when doing `npm test`, it is possibly because you have not `npm install` all the packages for the exercise. 

```
> test
> jest ./*

sh: jest: command not found
```