Reference Error: Primordials is not defined

Some English grammar:

Recently, I had to setup my local environment to run gulp tasks. Since my machine had gulp 4.0.1 and node 12.18.4, I had issues setting up the environment. Although this could be fairly basic for someone who has dealt with gulp and node, felt it could be useful for someone who encounters the same scenario as me. Most importantly, during the setup process, there was an interesting error message that drove me mad - "Reference Error: Primordials is not defined" 

If you are a pedantic English Grammar freak, the message with a plural word followed by a singular verb might get on your nerves right away but, you are not alone. As a developer , I spent half a day wondering what the hell is "Primordials" and how the hell is relevant to the scenario on hand. To make matters worse, a quick google search of "Primordials" resulted in something like this -

"Primordial deities (known as the Protogenoi) are the first entities born into existence; they form the very fabric of the universe and as such are immortal."

Since I was dealing with something immortal, as a mortal being, I decided to blog!

Some basics:

Since the project was a few years old, I was sure it used an old version of node and gulp. I found the gulp version from the package.json. By the way, you can find the node or gulp version or, any module version using <module name> -v. So, gulp -v or node -v in the command prompt should get the respective module version: 



As any backend developer, who takes over front-end code  and that too once they see the gulpfile.js and the package.json the natural instinct would be to run gulp. So, this is the message I received -


No prizes for guessing that this error is because the node_modules folder is not present -


How to generate node_modules folder?

So, in order to generate the node_modules folder,  you can use the npm init but since I knew that this project was on node 3.9.1, I decided to execute npm install  --save-dev gulp@3.9.1 since this will not only install the concerned node version but also create the node_modules folder in the process -



Post-install, you can check the gulp version using gulp -v:



Based on my gulpfile, I could find a task named js:all. So, I executed the same - gulp "js:all". Then, I was presented with this error -  "Reference Error: primordials is not defined" 


Although I found a blog wherein the suggestion was to create a npm-shrinkwrap.json file that will pin down the version of graceful-fs, the suggestion didn't work for me (maybe, I need to delete the node_modules folder and try!). I was lucky to have a co-developer on whose machine the project was running fine on node v8.17.0. 

How to install multiple node versions and use or switch node versions using nvm?

Since I already had node 12.18.4, I had to use nvm to switch between different versions of node. Before that, in order to install node 8.17.0, I had to execute the following commands one after another:

1. nvm install 8.17.0 

2. nvm use 8.17.0

After the above commands were executed, I had two versions of node in my machine. You can check the list of node versions using: nvm list -

Now, when I executed the gulp task, I didn't get the "Reference Error: Primordials is not defined" message.

So, I presume the "primordial" in the error message refers to the correct version of a required module! 

If you are someone new to NodeJS, remember this secret, if something doesn't work as expected with node modules - "Always delete and re-generate node_modules folder mainly in case of module version change (downgrading or upgrading)" - Very similar to machine restart if nothing works as expected in Windows!

Comments